tags:

views:

82

answers:

3

Is there any special significance to defining constant data inside a structure as shown. This is from a 3rd party library.

typedef struct              
{           
    IntVB abc_number;           
    #define ABC_A   0x01    
    #define ADBC_E  0x02     
    IntVB asset;            
} StructA;
+6  A: 

Not really. They probably provide better significance to the programmer in that spot of the code.

Meaning that those constants are probably related to the items in that struct container, or to the behavior of the struct.

Luca Matteis
And in the case above it wont be even possible to access those constants at runtime, since they are only `#define`'s. Not sure what meaning do they have here.
PeterK
+1  A: 

No, they could be called without any scope

onof
+2  A: 

Agree with @Luca Matteis. They are probably defined there because they are relevant at that point in the code. The compiler doesn't treat them specially. In particular, they could be defined just before that structure and work just the same. There's no significance to them being inside it.

However, there is one thing to note, they are only valid after they are defined. So they can't be used earlier in the file. That could be significant. For instance, they could be defined differently before that point. (It's a bad idea to do that, but it's possible.)

cape1232
yes true but i dont see them being redifined anywhere in the rest of the file
ckv