home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.sys5.r3
- Path: sparky!uunet!mcsun!fuug!kiae!demos!sensor!dnb
- From: dnb@sensor.zgrad.su (Dmitri Belosludtsev)
- Subject: Re: Compiler wierdness alert...
- Organization: Firm "Orgland", Zelenograd, Russia.
- Date: Tue, 12 Jan 1993 13:51:41 GMT
- Message-ID: <1993Jan12.135141.14137@sensor.zgrad.su>
- X-Newsreader: TIN [version 1.1 PL8]
- References: <1252@bazooka.amb.org>
- Sender: usenet@sensor.zgrad.su (Usenet News Sender)
- Lines: 58
-
- Ti Kan (ti@bazooka.amb.org) in msg <1252@bazooka.amb.org> writes:
-
- > Consider the following program:
-
- > ----------------------------------
- > #include <stdio.h>
-
- > #pragma pack(1)
- > union foo {
- > char d1;
- > long d2;
- > };
- > #pragma pack()
-
- > struct bar {
- > char a;
- > char b;
- > char c;
- > union foo d;
- > };
-
- > main()
- > {
- > struct bar x;
-
- > /* display the relative offsets of struct bar members */
- > printf("\t%d %d %d %d\n",
- > (char *) &x.a - (char *) &x,
- > (char *) &x.b - (char *) &x,
- > (char *) &x.c - (char *) &x,
- > (char *) &x.d - (char *) &x);
- > }
- > ----------------------------------
-
- > Program output (Compiled with cc on 3.2v2 DS or or gcc 2.2.2):
-
- > 0 1 2 4
-
- > Program output (Compiled with cc 3.2v4 DS, or rcc on both 3.2v2 DS
- > and 3.2v4 DS):
-
- > 0 1 2 3
-
- > So, with cc on 3.2v4 or rcc in both versions, the compiler does not put
- > a pad byte after field "c" in struct bar, whereas with cc on
- > 3.2v2 DS or gcc, it does.
- [skipped...]
- I tried that programm with ISC Unix ver3.0
- gcc (version 1.37.1) results in:
- 0 1 2 4
- cc (C Software Development System 4.1.5 9/11/91) results in:
- 0 1 2 3
-
- No comments.
- --
- Dmitri Belosludtsev, Firm "Orgland", Zelenograd, Russia
- e-mail: dnb@sensor.zgrad.su, FIDO: 2:5020/60.6
-
-