Aug 20, 2003 #1 malladisk Programmer Joined Jun 14, 2001 Messages 69 Location US Hi, If I'm using a macro #define VAR what would be the default value assigned to VAR? Thanks, Sashi
Aug 20, 2003 #2 Salem Programmer Joined Apr 29, 2003 Messages 2,455 Location GB I don't think VAR is assigned any value All you can do with it is tell whether its defined or not Code: #ifdef VAR printf( "VAR is defined\n" ); #endif Upvote 0 Downvote
I don't think VAR is assigned any value All you can do with it is tell whether its defined or not Code: #ifdef VAR printf( "VAR is defined\n" ); #endif
Aug 20, 2003 Thread starter #3 malladisk Programmer Joined Jun 14, 2001 Messages 69 Location US Ok. Thanks, Sashi Upvote 0 Downvote
Aug 21, 2003 #4 chipperMDW Programmer Joined Mar 24, 2002 Messages 1,268 Location US VAR expands to nothing. That means the following: Code: #define VAR VAR int VAR VAR VAR some_func VAR( VAR int VAR x VAR VAR, VAR float VAR y VAR VAR VAR ) VAR; expands to: Code: int some_func( int x, float y ); Whereas if VAR hadn't been defined at all, you'd get a bunch of errors about it. Sometimes you'll see something like: Code: #if CONST_WORKS_CORRECTLY #define CONST const #else #define CONST #endif extern CONST int some_constant; so that CONST can expand to "const" or expand to nothing, depending on the value of some other macro (probably set in a config header). Upvote 0 Downvote
VAR expands to nothing. That means the following: Code: #define VAR VAR int VAR VAR VAR some_func VAR( VAR int VAR x VAR VAR, VAR float VAR y VAR VAR VAR ) VAR; expands to: Code: int some_func( int x, float y ); Whereas if VAR hadn't been defined at all, you'd get a bunch of errors about it. Sometimes you'll see something like: Code: #if CONST_WORKS_CORRECTLY #define CONST const #else #define CONST #endif extern CONST int some_constant; so that CONST can expand to "const" or expand to nothing, depending on the value of some other macro (probably set in a config header).