This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: using offsetof with g++


Hi,

On 6 Nov 2003, Gabriel Dos Reis wrote:

> | I see.  Although it remains to be seen if it's really worthwhile to add a
> | new language construct for something which can already be expressed quite
> | conveniently, just to work around this specific issue which also could be
> | fixed by relaxing the constraints on offsetof().
>
> I hear you but, it is not clear that "the something" is already
> expressed quite conveniently

I meant ctors for member initialization which, inside C++, seem quite
natural.  Inventing another mean to initialize members just to avoid
making the struct non-POD doesn't look like a good idea.

> and relaxing the constraints is a convenient work around.

That's indeed not clear.  But I see no basic problems with at least
allowing Joes (2).  Or even just nearly-POD structs (i.e. no virtual
methods, no ref members; basically C structs plus non-virtual member
functions).  Note that this alone would already solve most of the usual
user complaints about using offsetof() on C++ classes.

> Which is the reason of the basic question
>   Why do you want to take the offsetof a non-POD?

For exactly the same reasons you want to apply offsetof() to a C
struct.  Now you might ask further why someone would then want to make
this a non-POD struct.  I gave also reasons for that.  That is, I can
return with a question which has to be answered by people wanting to
restrict offsetof():

   Why not allow offsetof on a nearly-POD?

> It is not clear at all that an accumulation of work arounds to speicific
> issues makes a simpler language to learn, use and implement.

Actually the users are surprised by some of the issues of offsetof(), so
in fact the language as it is now is the one which is harder to learn.
(Note that I don't want to say that there are no reasons to forbid
offsetof() in some situations.  I understand them and they must be
explained to users.  But for instance in the above situation there are no
technical reasons to disallow it.)


Ciao,
Michael.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]