I think there is nothing to be said, just code:

---struct.c---:

#include <stdio.h>

struct empty {};

void compare( struct empty * e1, struct empty * e2 )
{
    if( e1 == e2 )
        printf("function compare:\tsame\n");
    else
        printf("function compare:\tdifferent\n");
}

int main( int argc, char **argv)
{
    struct empty    e1;
    struct empty    e2;

    printf("%p == %p ?\n", &e1, &e2);

    if( &e1 == &e2 )
        printf("inline compare:\t\tsame\n");
    else
        printf("inline compare:\t\tdifferent\n");

    compare(&e1, &e2);

    return 0;
}

--end of struct.c---

So there is nothing fancy, but:

$ gcc 0struct.c -O2 -Wall
$ ./a.out 
0x7fff3dd22fd8 == 0x7fff3dd22fd8 ?
inline compare:         different
function compare:       same

And I don't quite understand why those pointers are different in the main(),
but same in the compare().
What's more:

$ g++ 0struct.c -O2 -Wall
$ ./a.out 
0x7fffe438ebc7 == 0x7fffe438ebc6 ?
inline compare:         different
function compare:       different

This gives reasonable output.

$ gcc -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.3.4/work/gcc-4.3.4/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.3.4
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.4
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.4/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.4/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --enable-nls --without-included-gettext
--with-system-zlib --disable-checking --disable-werror --enable-secureplt
--enable-multilib --enable-libmudflap --disable-libssp --enable-libgomp
--enable-cld --disable-libgcj --enable-languages=c,c++,treelang,fortran
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.3.4 p1.0, pie-10.1.5'
Thread model: posix
gcc version 4.3.4 (Gentoo 4.3.4 p1.0, pie-10.1.5)
$ uname -a
Linux ShellBullet 2.6.31-gentoo-r6 #1 SMP Wed Nov 25 15:33:12 CET 2009 x86_64
Intel(R) Core(TM)2 CPU 4300 @ 1.80GHz GenuineIntel GNU/Linux


-- 
           Summary: Gcc and pointers to empty structures.
           Product: gcc
           Version: 4.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: elmopl at gmail dot com
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42174

Reply via email to