delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/08/27/21:13:57

From: terry AT aegis DOT larc DOT nasa DOT gov
Date: Sat, 28 Aug 93 00:41:32 GMT
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Structure alignment

 
 
I need to pass data (via an interrupt routine) to a 16-bit application.
The data is in a structure that has chars mixed in with ints and floats.
I'd like a workaround from the 4-byte alignment.  Peter Crowley,
Quarterdeck Offices Systems (pcrowley AT qdeck DOT com), had a suggestion 
several months ago on using "__attribute__ ((packed))" to do this.  
I have tried both his example and the one shown below, both with the 
same results.  GCC crashes before it can finish compiling.  I am using
gcc version 2.2.2 (DJ's 1.09), straight C code.  Am I doing something
wrong or is this not do-able?  I'd appreciate any suggestions.
 
Terry Abbott
terry AT aegis DOT larc DOT nasa DOT gov
 
 
/***************  BEGIN PROGRAM  **************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define PACKED __attribute__ ((packed));
 
struct s_attach 
{ short  s;
  long   i PACKED;
};
 
void  main(void)
{ printf("%d\n",sizeof(struct s_attach));
}
/****************  END PROGRAM  ***************************/
 
 
The following is the is what the screen looks like:
 
        gcc -c -g -Wall MAIN.c
Segmentation violation in pointer 0x0000002c at 40:520ef
Expection 14 (0xe) at eip=520ef
    
         

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019