The standard defines array type meticulously, but I don't see any definition for array.
We might say "object of array type", however that can't be right as untyped objects (e.g. space allocated by malloc
) is described as an array.
Motivation: The specification for %s
in fprintf
(C11 7.21.6.1/8) says:
the argument shall be a pointer to the initial element of an array of character type
but take the code char s[] = "hello"; printf("%s", s+1);
then we passed a pointer to the second element. That definition appears to be assuming that array means any set of contiguous object(s).
Edit: seeing as I have picked up some "unclear what you're asking" votes, my question is: What is that definition of the term array as used by ISO/IEC 9899:2011 ?
Arrays are defined in the C Standard, 6.2.5, paragraph 20:
An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type. Array types are characterized by their element type and by the number of elements in the array. An array type is said to be derived from its element type, and if its element type is T, the array type is sometimes called ‘‘array of T’’. The construction of an array type from an element type is called ‘‘array type derivation’’.
来源:https://stackoverflow.com/questions/30546449/what-is-the-definition-of-array-in-c