public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Duft Markus" <Markus.Duft@salomon.at>
To: <gcc-help@gcc.gnu.org>
Subject: structure packing.
Date: Mon, 20 Oct 2008 07:33:00 -0000	[thread overview]
Message-ID: <18597F2B47F1394A9B309945EC72411201BD92CF@servex01.wamas.com> (raw)

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?

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/inc
lude
--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 $

             reply	other threads:[~2008-10-20  7:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-20  7:33 Duft Markus [this message]
2008-10-20  7:52 Duft Markus
     [not found] <ba0bd44d0905210723n5e6e85f5rea8b2b52c381d5d9@mail.gmail.com>
2009-05-21 14:39 ` Mohamed Shafi
2009-05-22  6:39   ` Ian Lance Taylor
2009-05-22  8:01     ` Mohamed Shafi
2009-05-22 13:51       ` Ian Lance Taylor
2014-01-16 10:45 vijay nag
2014-01-16 11:34 ` David Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18597F2B47F1394A9B309945EC72411201BD92CF@servex01.wamas.com \
    --to=markus.duft@salomon.at \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).