- #1
- 2,795
- 21
I know that it's often considered better practice to use C's "typed constants" instead of "#define" as it may offer better error/type checking. I'm wondering however what happens if a const is used to declare the size of an array. For example consider the two possible methods below.
The latter doesn't compile in standard C as it doesn't seem to recognize ListSize as a compile-time constant. It does however compile ok in c++, but I'm wondering if it does actually allocate the size specified (80 in this case) right there at compile time?
Does anyone know the nitty gritty on this?
Thanks.
Code:
#define ListSize 80
typdef int List[ListSize];
Code:
const int ListSize = 80;
typdef int List[ListSize];
The latter doesn't compile in standard C as it doesn't seem to recognize ListSize as a compile-time constant. It does however compile ok in c++, but I'm wondering if it does actually allocate the size specified (80 in this case) right there at compile time?
Does anyone know the nitty gritty on this?
Thanks.
Last edited: