A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nativelibs4java/nativelibs4java/issues/320 below:

long in struct causes incorrect align on 32-bit linux (BridJ) · Issue #320 · nativelibs4java/nativelibs4java · GitHub

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:

( 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)." )


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4