home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / gnu / gcc / help / 2113 < prev    next >
Encoding:
Text File  |  1992-09-11  |  1.6 KB  |  53 lines

  1. Newsgroups: gnu.gcc.help
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!jvnc.net!nj.nec.com!zilla
  3. From: zilla@ccrl.nj.nec.com (John Lewis)
  4. Subject: suncc vs gcc align
  5. Message-ID: <1992Sep12.033619.4117@research.nj.nec.com>
  6. Sender: news@research.nj.nec.com
  7. Organization: C&C Research Labs, NEC USA, Princeton, N.J.
  8. Distribution: gnu
  9. Date: Sat, 12 Sep 92 03:36:19 GMT
  10. Lines: 41
  11.  
  12. Hi, 
  13. In recompiling a file under gcc 2.2.2 (on sparc2), it seems like gcc
  14. is handling double alignment in a structure differently 
  15. than previous versions.  
  16. The file needs to be linked with some files compiled with the 
  17. normal sun cc; thus I specified -fpcc-struct-return, which did not help.
  18.  
  19. The following self-contained program illustrates the problem.
  20. The program runs using the sun cc compilation line but fails with a
  21. buss error when run with either of the gcc lines.  
  22. ================
  23. /*% cc % -o junk %*                             OK
  24.  *% gcc % -o junk %*                            BUS ERROR
  25.  *% gcc -fpcc-struct-return % -o junk %*        BUS ERROR
  26.  */
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30.  
  31. struct S_Flonum {            /* structure containing double */
  32.     int tag;
  33.     double val;
  34. };
  35.  
  36. typedef unsigned Object;
  37. #define FLONUM(x)   ((struct S_Flonum *)(x))
  38.  
  39. main() {
  40.   char *p;
  41.   Object num;
  42.   unsigned long a;
  43.  
  44.   p = malloc(sizeof(struct S_Flonum) + 100);  /* result is 8-aligned */
  45.   p += 4;                                     /* make it aligned on 4*/
  46.  
  47.   num = (int)p;
  48.   FLONUM(num)->val = 3.1415927;        /* BUSS ERROR here if 4-aligned */
  49.   a = (unsigned long)&(FLONUM(num)->val);
  50.   printf("val @ %d, 4=%d,8=%d\n",a,4*(a/4),8*(a/8)); fflush(stdout);
  51.   printf("val=%f\n",FLONUM(num)->val);
  52. }
  53.