Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!lll-winken!ames!ucsd!pacbell.com!pacbell!att!hriso!attdso!ssc!pilchuck!dataio!gtenmc!ravim From: ravim@gtenmc.UUCP (ravim) Newsgroups: comp.lang.c Subject: Nesting of a preprocessor directive within a macro defn Keywords: macro, nesting Message-ID: <849@gtenmc.UUCP> Date: 24 Aug 90 23:32:17 GMT Reply-To: ravim@gtenmc.UUCP (Ravi Kumar Mandava) Distribution: usa Organization: GTE Telecom, Inc. Bothell, WA Lines: 41 Is nesting of a preprocessor directive within a macro definition (RHS) not allowed? The following piece of code causes an error at the time of compilation. #define RET_NULL(str) return( \ #ifdef DEBUG (void) printf("DEBUG: %s\n", str), \ #endif (char *) 0) Upon running preprocessor, it dawned upon me that the compiler expanded RET_NULL macro as 'return( #ifdef DEBUG', and then gave syntax error at the next line, that is, '(void) printf ...'. The only way I could it make work properly is as follows: #ifdef DEBUG #define RET_NULL(str) return( \ (void) printf("DEBUG: %s\n", str), \ (char *) 0) #else #define RET_NULL(str) return((char *) 0) #endif The compiler I used is on Vax System V.3 (8810). Do any of the other compilers provide embedding a preprocessor directive within a macro definition? Is this allowed in standard C (old style or ANSI-style) syntax? I would be glad to know if someone could point out a better solution. Thanks. - Ravi (ravim@gtenmc.UUCP || ravim@gtenmc.gtetele.com)