J
jacob navia
I am trying to test the containers library in different environments
One of those is SUN sparc, that crashes when a double is accessed
in an address not multiple of 8. I got an access to an old one:
: ~/ccl ; uname -a
SunOS 5.9 Generic_118558-25 sun4u sparc SUNW,Sun-Fire-V210
Now, I have a list container with elements that
have this structure:
typedef struct _ListElement {
struct _ListElement *Next;
char Data[MINIMUM_ARRAY_INDEX]; // Generic storage...
} ListElement;
If I store double data in the "Data" member the machine will
crash since apparently it is a 32 bit SPARC, and the start of Data
is NOT aligned to an eight byte boundary.
One solution (albeit very ugly) is:
typedef struct _ListElement {
struct _ListElement *Next;
double alignment1;
char Data[MINIMUM_ARRAY_INDEX]; // Generic storage...
} ListElement;
This works. The compiler will correctly align "Data" and I
can safely store doubles into it. But this solutions is VERY
expensive since for EACH element I am spending 8 bytes
in alignment...
Is there another solution?
The "Data" member MUST be the last since it is a variable length
structure.
Thanks in advance for any pointers.
jacob
P.S. If anyone knows that system, gcc warns me
warning: implicit declaration of function 'snprintf'
I do include stdio.h...
What else should I include for getting snprintf?
Note that the link works, the function exists.
My compile options are:
gcc -std=c99 -I. -g -DUNIX -c sequential.c
One of those is SUN sparc, that crashes when a double is accessed
in an address not multiple of 8. I got an access to an old one:
: ~/ccl ; uname -a
SunOS 5.9 Generic_118558-25 sun4u sparc SUNW,Sun-Fire-V210
Now, I have a list container with elements that
have this structure:
typedef struct _ListElement {
struct _ListElement *Next;
char Data[MINIMUM_ARRAY_INDEX]; // Generic storage...
} ListElement;
If I store double data in the "Data" member the machine will
crash since apparently it is a 32 bit SPARC, and the start of Data
is NOT aligned to an eight byte boundary.
One solution (albeit very ugly) is:
typedef struct _ListElement {
struct _ListElement *Next;
double alignment1;
char Data[MINIMUM_ARRAY_INDEX]; // Generic storage...
} ListElement;
This works. The compiler will correctly align "Data" and I
can safely store doubles into it. But this solutions is VERY
expensive since for EACH element I am spending 8 bytes
in alignment...
Is there another solution?
The "Data" member MUST be the last since it is a variable length
structure.
Thanks in advance for any pointers.
jacob
P.S. If anyone knows that system, gcc warns me
warning: implicit declaration of function 'snprintf'
I do include stdio.h...
What else should I include for getting snprintf?
Note that the link works, the function exists.
My compile options are:
gcc -std=c99 -I. -g -DUNIX -c sequential.c