Let's say, I have in a C application a structure:
typedef struct {
int aParameter;
int anotherParameter;
} Structure_t;
and an array of Structure_t
elements:
const Structure_t arrayOfStructres[] = {
{
.aParameter = 1,
.anotherParameter = 2
},
{
.aParameter = 3,
.anotherParameter = 4
},
};
The arrayOfStructures
is constant, so no changes during runtime. This means, that theoretically the number of elements in the array is known during compilation time. I know I could calculate the number of elements with
sizeof(arrayOfStructures) / sizeof(arrayOfStructes[0]);
during runtime, but how to get the number of elements during compilation time with the preprocessor? As the number of elements may be much more than just the two in the example, counting every element when some are added or removed is not very fast and also error prone.