home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.gcc.help
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!jvnc.net!nj.nec.com!zilla
- From: zilla@ccrl.nj.nec.com (John Lewis)
- Subject: suncc vs gcc align
- Message-ID: <1992Sep12.033619.4117@research.nj.nec.com>
- Sender: news@research.nj.nec.com
- Organization: C&C Research Labs, NEC USA, Princeton, N.J.
- Distribution: gnu
- Date: Sat, 12 Sep 92 03:36:19 GMT
- Lines: 41
-
- Hi,
- In recompiling a file under gcc 2.2.2 (on sparc2), it seems like gcc
- is handling double alignment in a structure differently
- than previous versions.
- The file needs to be linked with some files compiled with the
- normal sun cc; thus I specified -fpcc-struct-return, which did not help.
-
- The following self-contained program illustrates the problem.
- The program runs using the sun cc compilation line but fails with a
- buss error when run with either of the gcc lines.
- ================
- /*% cc % -o junk %* OK
- *% gcc % -o junk %* BUS ERROR
- *% gcc -fpcc-struct-return % -o junk %* BUS ERROR
- */
-
- #include <stdio.h>
- #include <stdlib.h>
-
- struct S_Flonum { /* structure containing double */
- int tag;
- double val;
- };
-
- typedef unsigned Object;
- #define FLONUM(x) ((struct S_Flonum *)(x))
-
- main() {
- char *p;
- Object num;
- unsigned long a;
-
- p = malloc(sizeof(struct S_Flonum) + 100); /* result is 8-aligned */
- p += 4; /* make it aligned on 4*/
-
- num = (int)p;
- FLONUM(num)->val = 3.1415927; /* BUSS ERROR here if 4-aligned */
- a = (unsigned long)&(FLONUM(num)->val);
- printf("val @ %d, 4=%d,8=%d\n",a,4*(a/4),8*(a/8)); fflush(stdout);
- printf("val=%f\n",FLONUM(num)->val);
- }
-