gcc does not like the following code:
inline const plus(unsigned x,unsigned y) __attribute__((pure));
inline const plus(unsigned x,unsigned y) { return x+y; }
int arr[plus(1,1)];
it throws the following error:
error: variably modified ‘arr’ at file scope
The only thing is, I have done everything I can think of to tell gcc that it can optimize a call to plus(a,b) to "a+b" and I have only passed constants, so the result should be constant!
Am I missing something to make this work? Or is gcc just not that smart?
By the way, the reason for using plus(1,1) instead of 1+1 is that it makes for more generic construction of the array size using macros.
plushas no return type. Also, you need a constant expression, which the result of a function call is not. (In C++11 you can do something else that'll make it work.)