lxusr
lxusr

Reputation: 1007

What will be the scope of a MACRO defined inside a structure?

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

Answers (3)

Jens Gustedt
Jens Gustedt

Reputation: 78923

A macro definition remains for the whole remainder of the compilation, and macros aren't scoped.

Upvotes: 3

m0skit0
m0skit0

Reputation: 25873

Macros are pre-processor directives, they don't have scope.

Upvotes: 0

MByD
MByD

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

Related Questions