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/355: Compiler takes up an extra 4 bytes when using double in an union in a structure



>Number:         355
>Category:       c
>Synopsis:       Compiler takes up an extra 4 bytes when using double in an union in a structure
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 27 23:36:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Gordon Heydon
>Release:        gcc 2.95.2 from the precompiled versions.
>Organization:
>Environment:
AIX 4.3.3
>Description:
The problem is that when you compile a program where it has a union inside a structure which contains a double the structure take up an extra 4 bytes. The is a problem because this structure is being returned to my program from a library not compiled with gcc, and doesn't have this extra 4 bytes before the union. The attached program is what I used to determine what was causing the displacement. I was compileing with cc and the with gcc to see the difference. 
>How-To-Repeat:
just do a gcc a.c and run.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="a.c"
Content-Disposition: inline; filename="a.c"

#include <stdio.h>

typedef struct xxx
{
   char xxx[4];
   union
   {
      double dbl;
      float flt;
   } uValue;
} test;


int main(int argc, char *argv)
{
   printf("%d\n",sizeof(test));
}

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