This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: invalid offsetof from non-POD type
- From: Arnold Cole <y09kpa at yahoo dot com>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 11 Sep 2003 20:28:50 -0700 (PDT)
- Subject: Re: invalid offsetof from non-POD type
This is regarding a thread from Apr 2003. At that time
someone complained against this warning issued by the
C compiler.
Apparently the standard mandates that 'offsets may
only be applied to POD types. [18.1]/5'
While this may be so, it doesn't solve my coding
problem and doesn't explain to me why my class, with a
user-defined constructor (hence not a POD - whatever
this is) may not be used in offsetof. In my mind,
offsetof stands just on the same level as sizeof.
There are legitimate uses for them both, regardless of
user defined constructor.
While gcc 3.2 issues the warning, I figured a way to
redefine the macro such that it doesn't complain
anymore. Here it is for you guys out there to use it,
until we all agree whether offsetof is good or bad to
use.
#define offsetof(cls,member) (((size_t)&((cls
*)0x100->member)-0x100)
The trick is to use 0x100 (or any other value) instead
of 0. I used 0x100 to avoid any potential alignment
issues.
If any of the standard gurus out there would care to
explain to me why offsetof shouldn't work for non POD
types (and what POD types are), I'd appreciate it.
All the best!
Adrian
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com