-
Notifications
You must be signed in to change notification settings - Fork 83
Closed
Labels
Description
long in struct causes incorrect align on 32-bit linux
if I pass this struct in to a method:
typedef struct learn_parm {
double svm_c;
double double3;
long type;
double double2;
} LEARN_PARM;
which method looks like:
void printLearnParm(LEARN_PARM *learn_parm ) {
printf("svm c %lf kerneltype %ld double2 %lf double3 %lf\n", learn_parm->svm_c,
learn_parm->type, learn_parm->double2, learn_parm->double3 );
}
... then the first 2 doubles print correctly, whereas the third one is garbage.
I think that this is because the 'long' field causes incorrect alignment/padding for subsequent fields.
Environment: ubuntu linux 12.04, 32-bit
Note that this is still unsolved in bridj-0.6.2-20120618.225518-13.jar snapshot
Note that adding one additional long before the last double causes the last double to display correctly.
What I think is happening:
- the project is developed on Windows
- on Windows, alignment is to 8-bytes for doubles
- on linux, doubles are aligned on 4-byte boundaries
( http://en.wikipedia.org/wiki/Data_structure_alignment: "A double (eight bytes) will be 8-byte aligned on Windows and 4-byte aligned on Linux (8-byte with -malign-double compile time option)." )