🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by John Lewis Mon, 07 Sep 1992 06:26
suncc/gcc double in struct
#1075
Author: John Lewis
Date: Mon, 07 Sep 1992 06:26
41 lines
1768 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);
}
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