structure packing.
Duft Markus
Markus.Duft@salomon.at
Mon Oct 20 07:52:00 GMT 2008
>
> Hi!
>
> I have a strange problem with some of my source code. I have something
> similar as the small test case below, which I compile with multiple
> different compilers (and compiler versions), including visual c++
2003,
> 2005 and 2008 and GCC 3.3 and 4.2.
>
> It seems that gcc 4.2 makes some troubles ;) could please somebody
take
> a look at the things below, and tell me wether I'm just blind and
dumb,
> or there is a problem with gcc?
Some more testing revealed that using the gcc_struct attribute
additionally, makes it work.... is there any explanation for this? I
thought gcc_struct would be the default? (btw. I _am_ on windows, but
using interix, which I think should be pretty much unix, and nearly no
windows...).
Cheers, Markus
>
> Thanks in advance, Cheers, Markus
>
> mduft build $ cat zz.c
> #include <stdio.h>
>
> typedef struct __attribute__((packed, aligned(2))) {
> unsigned int a;
> unsigned short b;
> unsigned int c;
> } teststruct;
>
> int main(void) {
> printf("uint: %d, ushort: %d, struct: %d (should be %d)\n",
> sizeof(unsigned int), sizeof(unsigned short),
> sizeof(teststruct),
> (sizeof(unsigned int) * 2) + sizeof(unsigned short));
> }
> mduft build $ gcc zz.c
> mduft build $ ./a.out
> uint: 4, ushort: 2, struct: 12 (should be 10)
>
> mduft build $ gcc -v
> Using built-in specs.
> Target: i586-pc-interix6.0
> Configured with: /opt/gentoo.system/var/tmp/portage/sys-devel/gcc-
> 4.2.4-r00.1/work/gcc-4.2.4/configure --prefix=/opt/gentoo.system/usr
--
> bindir=/opt/gentoo.system/usr/i586-pc-interix6.0/gcc-bin/4.2.4 --
> includedir=/opt/gentoo.system/usr/lib/gcc/i586-pc-
> interix6.0/4.2.4/include --datadir=/opt/gentoo.system/usr/share/gcc-
> data/i586-pc-interix6.0/4.2.4 --
> mandir=/opt/gentoo.system/usr/share/gcc-data/i586-pc-
> interix6.0/4.2.4/man --infodir=/opt/gentoo.system/usr/share/gcc-
> data/i586-pc-interix6.0/4.2.4/info --with-gxx-include-
> dir=/opt/gentoo.system/usr/lib/gcc/i586-pc-
> interix6.0/4.2.4/include/g++-v4 --host=i586-pc-interix6.0
--build=i586-
> pc-interix6.0 --disable-altivec --disable-nls --with-system-zlib --
> disable-checking --disable-werror --enable-secureplt
--disable-multilib
> --disable-libmudflap --disable-libssp --disable-libgcj --enable-
> languages=c,c++,treelang --enable-shared --enable-threads=posix
--with-
> local-prefix=/opt/gentoo.system/usr
> Thread model: posix
> gcc version 4.2.4 (Gentoo 4.2.4-r00.1 p1.0)
>
> mduft build $ /opt/gcc.3.3/bin/gcc zz.c
> mduft build $ ./a.out
> uint: 4, ushort: 2, struct: 10 (should be 10)
> mduft build $
More information about the Gcc-help
mailing list