Reputation: 2258
Sometimes I see a define
preprocessor but not value assigned to it. For example:
#define VAR
What is assigned to VAR
when no value is specified?
I am also reading a text and I see:
#ifndef ERROR_FUNCTIONS_H
#define ERROR_FUNCTIONS_H
/* Error diagnostic routines */
void errMsg(const char *format, ...);
#ifdef __GNUC__
/* This macro stops 'gcc -Wall' complaining that "control reaches
end of non-void function" if we use the following functions to
terminate main() or some other non-void function. */
#define NORETURN __attribute__ ((__noreturn__))
#else
#define NORETURN
#endif
Is ERROR_FUNCTIONS_H
a header file? Or is that just a constant defined by define
preprocessor?
Upvotes: 1
Views: 2173
Reputation: 6049
It is just 'defined' so you can do checks like #ifdef ERROR_FUNCTIONS_H
So if you have
#define ERROR_FUNCTIONS_H
You can later do:
#ifdef ERROR_FUNCTIONS_H
//do something
#endif
and the code inside the #ifdef will be compiled.
ERROR_FUNCTIONS_H
is not a header file. It is just a #define
for the preprocessor to use.
What you have in your example:
#ifndef ERROR_FUNCTIONS_H
#define ERROR_FUNCTIONS_H
is often put at the top of a .h file to make sure it is only included once so you don't get multiple defines.
Upvotes: 3