PRB: Concatenation Symbol (##) Yields ErrorsArticle 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
Keywords : kbCompiler Version : MS-DOS:6.0,6.00a,6.00ax,7.0;WINDOWS:1.0,1.5,1.51 WINDOWS NT:1.0,2.0,2.1,2.2,4.0,4.1,4.2,5.0 Platform : MS-DOS NT WINDOWS Issue type : kbprb |
|
Last Reviewed: August 28, 1997 © 1999 Microsoft Corporation. All rights reserved. Terms of Use. |