Reputation: 1007
I came across the below declaration ; what will be the scope of this MACRO ?
typedef struct Hdr_s {
#define MACRO1 1
#define MACRO2 2
#define MACRO3 3
unsigned char Flag;
unsigned char Offset;
unsigned short cpy_len_offset;
unsigned char cpy_offset;
}Hdr_t;
Upvotes: 0
Views: 805
Reputation: 78923
A macro definition remains for the whole remainder of the compilation, and macros aren't scoped.
Upvotes: 3
Reputation: 137362
There is no "scope" for macros, once they are defined they exist until the end of the compilation unit. (or until #undef
).
The scope of blocks enclosed by brackets is defined by the compiler, while the macros are replaced before the compilation.
Upvotes: 0