This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: using offsetof with g++
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Trevor Blackwell <tlb at anybots dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: 04 Jun 2004 05:41:58 +0200
- Subject: Re: using offsetof with g++
- Organization: Integrable Solutions
- References: <1086319758.40223.104.camel@tlb>
Trevor Blackwell <tlb@anybots.com> writes:
| > If you can persuade the C++ committee that offsetof is important not
| > only for legacy C code but also for new C++ code, then there's a good
| > chance that this restriction will be loosened in a future version of the
| > language. On the other hand, you can also expect to be asked why
| > you want to use offsetof instead of pointers-to-member. (And if you can
| > show that there are things you can't do with pointers to members, you
| > might find that people will prefer to solve the problem by removing
| > whatever limitation pointers to members have.)
|
| I've been having the same problem with offsetof. The thing I want to do
| that can't be done with member pointers is:
|
| struct B {
| int y;
| };
|
| struct A {
| int x;
| B b;
| };
|
| int A::*myptr1 = &A::x; // fine
| int A::*myptr2 = &A::b.y; // error
B* A::*myptr2 = &A::b; // fine
there has been a proposal to allow composition of point-to-member and
generic pointer to data member. And there still is a suggestion
to complete the set of operations on pointer to members.
myptr2 is an index into B. So if you get that index, then you can
also compose &A::b with &B::y and get the relative of B::y inside A.
-- Gaby