I've got a problem where Pelles is putting static variables that should be aligned on at least 4 byte boundaries into odd memory addresses. I've got one of the cases whittled down down quite a bit, and it's interesting.
// I include these even though I don't use them all, since that is
// what was included in the program that had alignment problems.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct _inputArgntfsState
{
double sum;
int actionType;
bool writeDoesntClear;
bool forReads;
bool forWrites;
bool changedInfo;
int convertedStreet;
} inputArgntfsState, IASS, *PIASS;
bool k = 0;
IASS x = {0}; // Makes us come out an an odd address.
//IASS x; // Will come out at the correct 4 byte address.
int main(int agrc, char **argv)
{
printf( "sizeof(k) = %d, &k = 0x%X,\n", sizeof(k), &k );
printf( "sizeof(x) = %d, &x = 0x%X,\n", sizeof(x), &x );
return 0;
}
Run the program and x is at an odd address (at least on my Intel WinXp machine). Comment out line 21 and uncomment out line 22 and x is at a nice 4 byte boundary. Now, admittedly line 21 does not technically fill out the entire structure on a per member basis, but that should not cause an alignment issue.
BTW, #pragma pack has no effect.
Thanks
Jack
Note that one may ponder whether or not the structure should be aligned on an 8 byte boundary versus 4 because of the double, but that's a different question.