I opened stddef.h
and saw this:
#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF
#ifdef __cplusplus
#define offsetof(s,m) ((size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m)))
#else
#define offsetof(s,m) ((size_t)&(((s*)0)->m))
#endif
#else
#define offsetof(s,m) __builtin_offsetof(s,m)
#endif
In branch of __cplusplus
(In case of C++ compiler) there is very strange implementation, I think it's redundant. Else branch (case of C compiler) has simpler calculation of field offset. And I tested it, it works. For what used this strange casts and type qualifiers in first case?