🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by John Lewis Fri, 11 Sep 1992 04:29
sun cc vs gcc structure
#1121
Author: 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);
}
Re: sun cc vs gcc structure
#1124
Author: Casper H.S. Dik
Date: Fri, 11 Sep 1992 08:32
31 lines
1690 bytes
zilla@nj.nec.com (John Lewis) writes:

>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
> */

>  p += 4;                                     /* make it aligned on 4*/

You mess with the structure alignment requirements. There is
no guarantee that your code will continue to work with Sun's
cc. (And it doesn't, if you use -dalign)
Gcc 2.x assumes that doubles are aligned on 8 byte boundaries.
That assumption holds, until people mess with the alignment.
Actually, I'm suprised that Sun's compiler doesn't do this by default.

Casper
-- 
						|	Casper H.S. Dik
						|	casper@fwi.uva.nl
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads