🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1121

sun cc vs gcc structure

#1121
From: John Lewis
Date: Fri, 11 Sep 1992 04:29
41 lines
1790 bytes
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);
}
Technical Details
Message-ID: <1992Sep11.042924.22002@research.nj.nec.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!nj.nec.com!zilla

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!nj.nec.com!zilla
From: zilla@nj.nec.com (John Lewis)
Subject: sun cc vs gcc structure
Message-ID: <1992Sep11.042924.22002@research.nj.nec.com>
Sender: gnulists@ai.mit.edu
Organization: C&C Research Labs, NEC USA, Princeton, N.J.
Distribution: gnu
Date: Fri, 11 Sep 1992 04:29:24 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 42