Reading the standard, I asked myself this question.Maybe I'm just being inattentive, or maybe the standard just doesn't say it directly.
The paragraph of the C17 standard(3.15 #1) says:
object
region of data storage in the execution environment, the contents of which can represent values.
and the beginning of the paragraph(6.2.5 #20)
An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type...”
If an array consists of objects, each of which is a data storage area, and the array itself is also a data storage area, then the array is an object.
I don't know if I'm right or wrong, but I think it's a good theory.
If I'm wrong, then explain why.
The C standard does not have a sentence that explicitly says an array is an object, but the standard does refer to arrays as objects in numerous places.
C 2018 6.3.2.1 3:
… an expression that has type “array of type” is converted… If the array object has register storage class, the behavior is undefined.
C 2018 6.5.2.1 2:
A postfix expression followed by an expression in square brackets
[]
is a subscripted designation of an element of an array object.
C 2018 6.5.6 9 (and similarly in 6.5.8 and 6.5.9):
… one past the last element of the array object…
C 2018 6.7.3.1 3:
… to point to a copy of the array object into which it formerly pointed…
C 2018 6.7.9 6:
… then the current object (defined below) shall have array type…
In 6.5.2.5 3, the standard tells us a compound literal “provides an unnamed object” that may be an array (6.5.2.5 4: “the type of the compound literal is that of the completed array type”).
Also, if an array were not an object, the standard would not have to exclude it from the definition of modifiable lvalue in 6.3.2.1 1:
An lvalue is an expression (with an object type other than void) that potentially designates an object;1… A modifiable lvalue is an lvalue that does not have array type,…
Further, 6.2.1 1 tells us that an identifier can denote “an object; a function; a tag or a member of a structure, union, or enumeration; a typedef name; a label name; a macro name; or a macro parameter.” If an array were not an object, its identifier would not denote any of these. So the identifier for an array must denote an object.
1 An example of an lvalue that does not designate an object is *p
where p
is a null pointer at the time of evaluation. *p
is an expression that potentially designates an object, but it requires a proper value for p
.