Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#define default value

Status
Not open for further replies.

malladisk

Programmer
Jun 14, 2001
69
US
Hi, If I'm using a macro
#define VAR
what would be the default value assigned to VAR?
Thanks,
Sashi
 
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
 
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).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top