home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / gnu / gcc / bug / 2315 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.7 KB  |  55 lines

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