sizeof of aligned struct different for nvcc and g++


I found a discrepancy in the sizeof operator in nvcc. If I compile the following program (test.cpp) using nvcc and g++ I get different results:


#include <stdio.h>

typedef struct {

unsigned int r, g, b;

} RGB32 attribute ((aligned (16)));

int main(void)


printf("Size of RGB32 is %d\n", (int)sizeof(RGB32));

return 0;



$ g++ test.cpp

$ ./a.out

Size of RBG32 is 12

$ cp test.cpp

$ nvcc

$ ./a.out

Size of RBG32 is 16

I am using nvcc 2.3, g++ 4.3, and Ubuntu 9.10 (Linux 2.6.31 x86_64).

I was wondering if anyone had seen this before. I haven’t had a chance to upgrade nvcc to 3.0 but I doubt the result will be different.

Thank you,


For the record, I found the problem to be the syntax to tell gcc to align the struct. The correct syntax is:

typedef struct attribute((aligned(16))) {
int r, g, b;
} RGB32;