Is this a valid form of typedef struct and if so, what does it mean?
Working with a piece of code right 开发者_Go百科now that features declarations of the form:
typedef PACKED(struct)
{
// some stuff in here
} struct_name;
now...PACKED is a macro on our part. What the heck does this syntax mean? I don't understand the use of parenthesis. This is not compiling, so I'm guessing this is probably incorrect. Is this close to some other valid syntax, or is it just nonsense?
If it is almost valid..how is this code actually supposed to be written and what is it supposed to mean?
The only form of typedef struct I've seen and can find online is:
typedef struct
{
// some stuff in here
} struct_name;
Solved: All I needed to realize was that struct was a parameter in a macro function. Thanks!
Usually something in all caps is a macro. In this case it's probably supposed to decorate the struct declaration with the syntax for creating a packed structure, which will vary based on the compiler used.
Chances are you're completely missing the definition of the PACKED macro.
Most compilers provide the functionality to specify how structures should be stored in memory. It's rarely used, but packed
usually means *have this structure occupy the least space possible, even at a loss of speed in accessing its members*
.
Given that your code doesn't compile, I'd say PACKED
was most likely a macro now lost, or a compiler-specific keyword not available in the one you're using.
With that syntax, PACKED has to be a macro.
Probably referring to some manner of struct alignment
__attribute__(packed, aligned(1))
#pragma pack(push,1)
//...
#pragma pack(pop)
though hard for us to tell you, as opposed to the reverse :))
精彩评论