This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: using offsetof with g++
I wrote:
> | It seems to me that there are four categories:
> |
> | 1) Those cases where ISO C++ specifies what the answer is.
> |
> | 2) Those cases where any reasonable implementation (and all
> | implementations we know of) give the right answer, but ISO
> | C++ says "undefined".
> |
> | 3) Those cases where we know that g++ will give the right answer,
> | but we can't be sure of other possible implementations.
> |
> | 4) Those cases where use of offsetof() is nonsense, since the offset
> | is not even constant.
On Thu, Nov 06, 2003 at 08:47:19PM +0100, Gabriel Dos Reis wrote:
> I don't know where you put my favorite example that involve
> references:
>
> int i;
>
> struct A {
> int& r;
> A() : r(i) { }
> };
>
> int main()
> {
> cout << offsetof(A, r) << endl;
> }
Case 4 (it will do the wrong thing).