tags:

views:

54

answers:

1

I want to make some static constants globally visible. I'm pretty familiar how to do that in C++. The problem is that these constants need to be aligned to some exotic boundary. Do I have to specify the alignment in extern declaration? I'm using GCC4.5

in *.cpp file

static const constant_t constant __attribute__((aligned(64))) = {blah,blah,blah};

in *.h file

//Which one is correct?
extern const constant_t constant;
extern const constant_t constant __attribute__((aligned(64)));
+3  A: 

First, it looks like you're trying to declare it static in the C file, which is the old C way of saying internal (file) linkage. This is inconsistent with your goal of making it global.

Given that the static is removed, you should only need the attribute in the C file: The extern declaration says effectively "I want to use this name, when you finally find out its address, substitute that in here". In other words, once the address is assigned at the definition point in the C file, your extern will symbolically point to that same address.

Mark B