Thursday, November 09, 2006

gcc offseof macro warning

Nathan Sidwell had this really neat trick that gets us around the gcc compiler warning on the usage of the offsetof macro.

Rather than using the offsetof macro, use the one below:

#define myoff(T,m) ((size_t)(&((T *)1)->m) - 1)

The trick is to use the address '1' rather than '0' (which the offsetof macro uses) and thus pacify gcc.

The issue of this compiler warning is a hotly debated issue.


No comments: