This is the mail archive of the gcc-bugs@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]

Re: constant calls and optimization


> The two following code snippets generate different code, in that the call
> will go to different memory addresses.
> 
> /* Wrong ?? */
> int my_foo(int i)
> {
>     return ((int (*)(int))0x12345678)(i);
> }
> 
> /* Right ? */
> int my_bar(int i)
> {
>     int (* volatile orig)(int) = (int (*)(int)) 0x12345678;
>     return orig(i);
> }

I can't reproduce this. With egcs-2.91.66 g++ -O2 -S -fno-exceptions
-fomit-frame-pointer, I get

        movl 4(%esp),%eax
        pushl %eax
        call 305419896
        addl $4,%esp
        ret

for foo, and I get

        subl $4,%esp
        movl 8(%esp),%eax
        movl $305419896,(%esp)
        pushl %eax
        movl 4(%esp),%eax
        call *%eax
        addl $4,%esp
        popl %ecx
        ret

for bar. This is surely different code, but it won't go to different
memory addresses. Where is the problem?

Martin


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