help-gplusplus
[Top][All Lists]
Advanced

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

cast, reference and reinterpret_cast


From: Frederic Mayot
Subject: cast, reference and reinterpret_cast
Date: 7 Feb 2007 12:45:07 -0800
User-agent: G2/1.0

Hi,
Can someone explain me why the following line of code does not compile
the same way on g++ 3.4.6 and g++ 4.1.1 in 64 bits:
(char*&)p += sizeof(A);
AND
p = reinterpret_cast<A*>(reinterpret_cast<char*>(p) + sizeof(A));

in the following context:
struct A {double c[4];};
A* p = reinterpret_cast<A*>(new char[sizeof(A)*2]);
// LINE
p->c[2] = 12.0;

GCC4/64
With first line
main:
.LFB2:
        subq    $24, %rsp
.LCFI0:
        movl    $64, %edi
        call    _Znam
        movabsq $4622945017495814144, %rdx
        movq    %rdx, 16(%rax)
        xorl    %eax, %eax
        addq    $24, %rsp
        ret

With second line
main:
.LFB2:
        subq    $8, %rsp
.LCFI0:
        movl    $64, %edi
        call    _Znam
        movabsq $4622945017495814144, %rdx
        movq    %rdx, 48(%rax)
        xorl    %eax, %eax
        addq    $8, %rsp
        ret


GCC3.4/64
main:
.LFB2:
        subq    $8, %rsp
.LCFI0:
        movl    $64, %edi
        call    _Znam
        movabsq $4623507967449235456, %rdx
        movq    %rdx, 48(%rax)
        xorl    %eax, %eax
        addq    $8, %rsp
        ret



reply via email to

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