I want to use the C preprocessor to count the amount of lines between two code locations. The basic idea is something like this:
#define START __LINE__
static char* string_list[] = {
"some string",
"another string",
...
"last string"
};
#define END __LINE__
#if END - START > 42
#error Too many entries
#endif
Of course this doesn't work because in this case START
and END
are merely redefinitions of the __LINE__
macro.
I was playing around a bit with the #
and ##
operators, but I could not get the preprocessor to evaluate START
and END
while the preprocessor is running.
My question is: is this possible at all?
Checking the size of the array during runtime is not an option.
Thanks for any hints or ideas in advance!