What, exactly, is numbers in the following declaration, if it is not an address constant?
int main() {
int numbers[3] = {1,2,3};
return 0;
}
Disassembling the program shows that 1, 2, and 3 are dynamically placed on the local stack space, rather than the whole array being treated as a constant. Hence, {1,2,3} does not have static storage duration, so numbers is not an address constant, as per the C99 spec.
C99, Section 6.6.9: “An address constant is a null pointer, a pointer to an lvalue designating an object of static storage duration, or a pointer to a function designator…”
However, adding the line numbers++ after the declaration causes the following compile error in GCC 4.1.2:
error: invalid lvalue in increment
So it is constant, but isn’t an address constant. Does anybody know the official name of this type of constant in C99 (or similar)?
numbersis a non-constant, automatic, array variable of the functionmain.Because it is automatic and non-constant it can not have static storage.
because it is an array variable (and not you’ll notice a pointer) it can not be incremented.
Note that you can do