PRB: Concatenation Symbol (##) Yields ErrorsLast reviewed: August 26, 1997Article ID: Q116449 |
The information in this article applies to:
SYMPTOMSThe ## preprocessing macro concatenates the arguments on either side of the "##". However, as stated in the "ANSI Specification," the resultant value must be a preprocessing token. If it is not, the compiler generates the following error messages:
C2065: 'token' : undefined C2146: syntax error : missing ')' before identifier 'token1' CAUSEThis is by design. The "ANSI Specification," section 3.8.3.3, page 91, states, regarding ##, that "If the result is not a valid preprocessing token, the behavior is undefined." These error messages are generated unless one of two things happens:
MORE INFORMATIONYou can use the sample code below to demonstrate how these error messages are generated. The intention of the code is to construct the text string "_fheapchk" by concatenating "_f" and "heapchk". Because _fheapchk is not a preprocessor token, the error occurs unless you use the /E option. NOTE: This example doesn't make much sense for 32-bit code, but it does illustrate the kind of problem this article is talking about.
Sample Code
/* Compile options needed: none */ #define DEFAULTMODEL() _f #define FUNCNAME_NA(prefix,func) prefix##func( ) void checkne_func(int a) { } void main(void) { checkne_func((int)(FUNCNAME_NA(DEFAULTMODEL(),heapchk))); } |
Additional query words: 8.00 8.00c 9.00 9.10 10.00 10.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |