I understand that you define a constant, using it later to determine the size of one or more arrays, and also want the constant to be a character, preferably without a messy namespace. (If it was a question of exporting the size of a single array, I would instead suggest sizeof(array) / sizeof(*array)
as missing).
static const int ASIZE = 10; #define ASIZE 10 int array[ASIZE];
There is a variable with the desired value that will be in the object file, but the preprocessor macro obscures it with the value itself, so the array definition will also be successful.
However, you may find the need to duplicate the expression of the value ugly. Would it be nice if we could define a variable in terms of a macro?
static const int ASIZE = #define ASIZE 10 ASIZE; int array[ASIZE];
I'm not sure if this is actually the best idea, not only the one above, but it works (and I could not get gcc to take offense at it) and does not contain duplication, except for the identifier. And this is funny.
source share