I have type:
typedef struct
{
int x;
int y;
int z;
} sdf_test_t;
But when I try to compile the following:
offset = offsetof(sdf_test_t, z);
Visual Studio responds with:
c:\dataflash.c(542) : error C2143: syntax error : missing ')' before 'type'
c:\dataflash.c(542) : error C2059: syntax error : ')'
What is wrong here?
I am using:
Microsoft Visual Studio 2008 x86
Microsoft (R) Visual Studio Version 9.0.21022.8.
The offsetof
macro is defined in <stddef.h>
as follows:
/* Define offsetof macro */
#ifdef __cplusplus
#ifdef _WIN64
#define offsetof(s,m) (size_t)( (ptrdiff_t)&reinterpret_cast<const volatile char&>((((s *)0)->m)) )
#else
#define offsetof(s,m) (size_t)&reinterpret_cast<const volatile char&>((((s *)0)->m))
#endif
#else
#ifdef _WIN64
#define offsetof(s,m) (size_t)( (ptrdiff_t)&(((s *)0)->m) )
#else
#define offsetof(s,m) (size_t)&(((s *)0)->m)
#endif
#endif /* __cplusplus */
By elimination. I've established that the compiler uses:
#define offsetof(s,m) (size_t)&reinterpret_cast<const volatile char&>((((s *)0)->m))