c/2588: Bad alignment when passing structure by value to function
exco@ligim.univ-lyon1.fr
exco@ligim.univ-lyon1.fr
Thu Apr 19 06:16:00 GMT 2001
>Number: 2588
>Category: c
>Synopsis: Bad alignment when passing structure by value to function
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Thu Apr 19 06:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Thierry EXCOFFIER
>Release: gcc version 2.95.3 20010315 (release)
>Organization:
>Environment:
IRIX b710sibn 6.5 01101246 IP32
>Description:
For some structure size, when the structure is
passed by value to a function, its content is incorrect.
>How-To-Repeat:
/* The problem always appear when size D+F > 16 and F odd */
#define D 14
#define F 3
typedef struct
{
int a[D] ;
} DoubleAlignment ;
typedef struct
{
int a[F] ;
} FloatAlignment ;
void display(FloatAlignment x, DoubleAlignment y)
{
int i ;
for(i=0;i<F;i++)
if ( x.a[i] != 100+i )
printf("ERROR : x.a[%d] = %d != %d\n", i, x.a[i], 100+i) ;
for(i=0;i<D;i++)
if ( y.a[i] != 200+i )
printf("ERROR : y.a[%d] = %d != %d\n", i, y.a[i], 200+i) ;
}
int main()
{
FloatAlignment x ;
DoubleAlignment y ;
int i ;
printf("D=%d F=%d\n", D, F) ;
for(i=0;i<F;i++)
x.a[i] = 100+i ;
for(i=0;i<D;i++)
y.a[i] = 200+i ;
display(x, y) ;
return(0) ;
}
>Fix:
Use -O3 option when compiling.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list