bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] test-stddef: test offsetof compliance


From: Bruno Haible
Subject: Re: [PATCH] test-stddef: test offsetof compliance
Date: Tue, 17 Aug 2010 02:04:37 +0200
User-agent: KMail/1.9.9

Paolo Bonzini wrote:
> >> #define offsetof(__a,__b) ((size_t)(&(((__a*)0)->__b)))
> In C, the macro will work in practice with all compilers.

In C++, however, some versions of g++ give a warning or error
if this macro is used for a type that is not a POD type (that is,
a type that has constructors or member functions or similar).
I ended up using this definition:

#if defined __GNUG__
  #define offsetof(type,ident)  ((size_t)&(((type*)1)->ident)-1)
#else
  #define offsetof(type,ident)  ((size_t)&(((type*)0)->ident))
#endif

Bruno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]