This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c/559: Alignment problem - difference to gcc 2.7.2



>Number:         559
>Category:       c
>Synopsis:       Alignment problem - difference to gcc 2.7.2
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          support
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 20 08:16:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Burkhard Schultheis
>Release:        2.95.2
>Organization:
>Environment:
AIX 4.3.3
>Description:
If you have a struct like
struct
{
 int a;
 int b;
 union
 {
   double c;
 } 
...
then element c has an offset of 8 byte. With version 2.7.2 on AIX 4.2.1 it was only 4 bytes. If you omit the union putting the double directly in the structure, there is an offset of 4, too.
We have a 3rd party library. And now the structure layout in the library is different from the layout in our module we link to this library. -fpack_struct does not help. What to do?
>How-To-Repeat:
#include <stdio.h>

typedef struct
{
 char a;
 char b;
 union
 {
  double d;
 } u;
} struktur;
  

int main (void)
{
 struktur teststruct;

 printf ("offset b: %d, offset d: %d\n",
   (int) &teststruct.b - (int) &teststruct,
   (int) &teststruct.u.d - (int) &teststruct);
 return (0);
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]