__attribute__ ((aligned(8))) doesn't work with typedefs

I'm currently using the February 2007 version of Sun Studio Express in order to get support for __attribute__ ((aligned(8))).

While trying to create a long long type that would be aligned to an 8 bytes boundary on x86 instead of the usual 4 bytes, I discovered that the __attribute__ ((aligned(8))) directive only works on variables, not on typedefs...

if I use:

long long __attribute__((aligned (8))) foo;

then foo is 8 bytes aligned as expected.

If I use:

typedef __attribute__ ((aligned (8))) long long bar;

bar foo;

then foo is 4 bytes aligned instead of the expected 8.

This behavior is not present in gcc where foo will get an 8 bytes alignment in both cases. Is there any way to fix this or to make it works?

[777 byte] By [StephanePotvina] at [2007-11-26 21:36:44]
# 1
Can you show me a full testcase - declaration, compilation line and a way how you check the alignment.I was not able to reproduce your observation right away. My "foo" is perfectly aligned ;)regards,__Fedor.
SFVa at 2007-7-10 3:18:22 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Here's a sample program that reproduce the problem here.

spotvin@tl-sol10i64-01 % cat testalign.c

[code]

#include <stdio.h>

typedef __attribute__ ((aligned(8))) long long aligned_longlong_t;

struct typedef_longlong {

unsigned intdummy;

aligned_longlong_tlonglong;

};

struct manual_longlong {

unsigned intdummy;

long long __attribute__ ((aligned(8))) longlong;

};

int

main (void)

{

printf("sizeof(struct typedef_longlong) = %d\n", sizeof(struct typedef_longlong));

printf("sizeof(struct manual_longlong) = %d\n", sizeof(struct manual_longlong));

return 0;

}

[/code]

spotvin@tl-sol10i64-01 % suncc -V

cc: Sun C 5.9 SunOS_i386 Build40_1 2007/02/08

usage: cc [ options] files. Use 'cc -flags' for details

spotvin@tl-sol10i64-01 % suncc -o testalign testalign.c

spotvin@tl-sol10i64-01 % ./testalign

sizeof(struct typedef_longlong) = 12

sizeof(struct manual_longlong) = 16

StephanePotvina at 2007-7-10 3:18:22 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
Yeah, there were problems with typedef'ing aligned attribute and then doing derived types from it.Right now this problem is being worked on.There is a good chance for the fix to get its way into release. You can cross fingers for it ;)regards,__Fedor.
SFVa at 2007-7-10 3:18:22 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4
Thanks for the quick feedback!I hope they do fix it as it's kind of a pain to manually align all structures with dummy fields to make the memory layout of a struct match for both x86 and sparc... (which aligns long long on 8 bytes boundary).
StephanePotvina at 2007-7-10 3:18:22 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5

Just to let you know - this problem is fixed in Sun Studio 12 release:

] suncc -o testalign testalign.c -V

cc: Sun C 5.9 SunOS_i386 2007/05/03

acomp: Sun C 5.9 SunOS_i386 2007/05/03

ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.553

] ./testalign

sizeof(struct typedef_longlong) = 16

sizeof(struct manual_longlong) = 16

]

regards,

__Fedor.

SFVa at 2007-7-10 3:18:22 > top of Java-index,Development Tools,Solaris and Linux Development Tools...