When using a global array of structs i have identified the following bug:
1. The struct has two members of any kind
2. when you assing a value to the first member the second member gets overwritten, in fact the next 4 bytes get overwritten
so if you have 4 chars they all get overwritten
3.This only happens if you have a global array struct defined out of scope
4. If the array is of size 1 the bug does not appear, size must be 2 or more
My sscce:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct test_s
{
float val ;
int bol ;
} ;
#define LEN 5
struct test_s mystr[LEN] ;
int main( void )
{
for( int i = 0 ; i < LEN ; i += 1 )
{
mystr[i].val = 321.0f ;
mystr[i].bol = 1 ;
}
for( int i = 0 ; i < LEN ; i += 1 )
printf( "\n %f %d" , mystr[i].val , mystr[i].bol ) ;
for( int i = 0 ; i < LEN ; i += 1 )
mystr[i].val = 0.0f ; //set only val to 0
for( int i = 0 ; i < LEN ; i += 1 )
printf( "\n %f %d" , mystr[i].val , mystr[i].bol ) ; //both values get printed as 0, WRONG!
return 0;
}
Output should be
http://ideone.com/qWpKPF321.000000 1
321.000000 1
321.000000 1
321.000000 1
321.000000 1
0.000000 1
0.000000 1
0.000000 1
0.000000 1
0.000000 1
but is
321.000000 1
321.000000 1
321.000000 1
321.000000 1
321.000000 1
0.000000 0
0.000000 0
0.000000 0
0.000000 0
0.000000 0
Can someone please verify this on their version of Pelles IDE.
MY system: Windows 7 32 bit Professional, Service Pack 1 ( Build 7601 ), Pelles Version 7.00.355