Originally posted by: KingNothing
Originally posted by: Spamela
it's calculating the offset in bytes of the element w of struct z.
i.e., the macro calculates that w is 4 + 8 = 12 bytes from the first byte of
a struct z (assuming no byte padding)
typedef struct
{
int a;
double b;
int w;
} z;
Can you post sample code illustrating this? I can't get his macro to compile.
BTW,
dude8604, are you sure you typed the code exactly right?
here goes (but i think the contest was won already).
i'd seen this #define before, but not named MAKE_COOL_GAMES
#pragma pack(1)
#define MAKE_COOL_GAMES(z, w) (int)(&(((z *)0)->w))
typedef struct
{
int a;
double b;
int c;
} Yow_t;
int _tmain(int argc, _TCHAR* argv[])
{
int iOffset = MAKE_COOL_GAMES(Yow_t, a);
printf ("Offset of a is %d\n", iOffset);
iOffset = MAKE_COOL_GAMES(Yow_t, b);
printf ("Offset of b is %d\n", iOffset);
iOffset = MAKE_COOL_GAMES(Yow_t, c);
printf ("Offset of c is %d\n", iOffset);
return 0;
}