offsetof cannot be evaluated at compile time: not an integral constant-expression
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lsb |
Fix Committed
|
Medium
|
Unassigned | ||
Mandriva |
Fix Released
|
Medium
|
Bug Description
LSB SDK declares the offsetof macro in the following way:
#define offsetof(
In general, this works fine, but there are some specific cases when such
implementation can lead to compilation errors. In particular, the following
example will compile with LSB SDK using gcc 3.x and fail if gcc 4.x is used:
/******
struct testcase {
char array[256];
};
int main(void) {
char buffer[ offsetof( struct testcase, array[0])];
return 0;
}
/******
error: size of array ‘buffer’ is not an integral constant-expression
This is actually a break between gcc-3* and gcc-4* which was introduced after
fixing this issue:
http://
And in gcc 4.x, offsetof is declared in the following way:
#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
Not sure how this can be handled in LSB SDK; the first idea that comes to my
mind is to simply check if we are compiling with gcc 4.x and provide a
different offsetof declaration in this case.
However, in most cases the current offsetof implementation works fine, so
probably this is not a critical issue. Finally, there is a simple workaround,
at least for the example above:
int i = offsetof( struct testcase, array[0] );
char buffer[i];
Changed in mandriva: | |
importance: | Unknown → Medium |
status: | Unknown → Fix Released |