@@ -2959,159 +2959,137 @@
2959
2959
\indextext {declarator!array}
2960
2960
2961
2961
\pnum
2962
- In a declaration
2963
- \tcode {T}
2964
- \tcode {D}
2965
- where
2966
- \tcode {D}
2967
- has the form
2962
+ In a declaration \tcode {T} \tcode {D} where \tcode {D} has the form
2968
2963
2969
2964
\begin {ncsimplebnf }
2970
2965
\terminal {D1} \terminal {[} \opt {constant-expression} \terminal {]} \opt {attribute-specifier-seq}
2971
2966
\end {ncsimplebnf }
2972
2967
2973
- and the type of the identifier in the declaration
2974
- \tcode {T}
2975
- \tcode {D1}
2976
- is
2977
- `` \placeholder {derived-declarator-type-list}
2978
- \tcode {T}'' ,
2979
- then the type of the identifier of
2980
- \tcode {D}
2981
- is an array type; if the type of the identifier of \tcode {D}
2982
- contains the \tcode {auto} \grammarterm {type-specifier},
2983
- the program is ill-formed.
2984
- \tcode {T}
2985
- is called the array
2986
- \term {element type};
2987
- this type shall not be a reference type, \cv {}~\tcode {void},
2988
- or a function type.
2989
- \indextext {declaration!array}%
2990
- If the
2991
- \grammarterm {constant-expression}\iref {expr.const }
2992
- is present, it shall be a converted constant
2993
- expression of type \tcode {std::size_t} and
2994
- its value shall be greater than zero.
2995
- The constant expression specifies the
2996
- \indextext {array!bound}%
2968
+ and the type of the contained \grammarterm {declarator-id}
2969
+ in the declaration \tcode {T} \tcode {D1}
2970
+ is `` \placeholder {derived-declarator-type-list} \tcode {T}'' ,
2971
+ the type of the \grammarterm {declarator-id} in \tcode {D} is
2972
+ `` \placeholder {derived-declarator-type-list} array of \tcode {N} \tcode {T}'' .
2973
+ The \grammarterm {constant-expression}
2974
+ shall be a converted constant expression of type \tcode {std::size_t}\iref {expr.const }.
2997
2975
\indextext {bound, of array}%
2998
- \term {bound}
2999
- of (number of elements in) the array.
3000
- If the value of the constant expression is
3001
- \tcode {N},
3002
- the array has
3003
- \tcode {N}
3004
- elements numbered
3005
- \tcode {0}
3006
- to
3007
- \tcode {N-1},
3008
- and the type of the identifier of
3009
- \tcode {D}
3010
- is `` \placeholder {derived-declarator-type-list} array of
3011
- \tcode {N}
3012
- \tcode {T}'' .
3013
- An object of array type contains a contiguously allocated non-empty set of
3014
- \tcode {N}
3015
- subobjects of type
3016
- \tcode {T}.
3017
- Except as noted below, if
3018
- the constant expression is omitted, the type of the identifier of
3019
- \tcode {D}
3020
- is `` \placeholder {derived-declarator-type-list} array of unknown bound of
3021
- \tcode {T}'' ,
3022
- an incomplete object type.
3023
- The type `` \placeholder {derived-declarator-type-list} array of
3024
- \tcode {N}
3025
- \tcode {T}''
3026
- is a different type from the type
3027
- `` \placeholder {derived-declarator-type-list} array of unknown bound of
3028
- \tcode {T}'' ,
3029
- see~\ref {basic.types }.
2976
+ Its value \tcode {N} specifies the \defnx {array bound}{array!bound},
2977
+ i.e., the number of elements in the array;
2978
+ \tcode {N} shall be greater than zero.
2979
+
2980
+ \pnum
2981
+ In a declaration \tcode {T} \tcode {D} where \tcode {D} has the form
2982
+
2983
+ \begin {ncsimplebnf }
2984
+ \terminal {D1 [ ]} \opt {attribute-specifier-seq}
2985
+ \end {ncsimplebnf }
2986
+
2987
+ and the type of the contained \grammarterm {declarator-id}
2988
+ in the declaration \tcode {T} \tcode {D1}
2989
+ is `` \placeholder {derived-declarator-type-list} \tcode {T}'' ,
2990
+ the type of the \grammarterm {declarator-id} in \tcode {D} is
2991
+ `` \placeholder {derived-declarator-type-list} array of unknown bound of \tcode {T}'' , except as specified below.
2992
+
2993
+ \pnum
2994
+ \indextext {declaration!array}%
2995
+ A type of the form `` array of \tcode {N} \tcode {U}'' or
2996
+ `` array of unknown bound of \tcode {U}'' is an \defn {array type}.
2997
+ The optional \grammarterm {attribute-specifier-seq}
2998
+ appertains to the array type.
2999
+
3000
+ \pnum
3001
+ \tcode {U} is called the array \defn {element type};
3002
+ this type shall not be
3003
+ a placeholder type\iref {dcl.spec.auto },
3004
+ a reference type,
3005
+ a function type,
3006
+ an array of unknown bound, or
3007
+ \cv {}~\tcode {void}.
3008
+ \begin {note }
3009
+ An array can be constructed
3010
+ from one of the fundamental types (except \tcode {void}),
3011
+ from a pointer,
3012
+ from a pointer to member,
3013
+ from a class,
3014
+ from an enumeration type,
3015
+ or from an array of known bound.
3016
+ \end {note }
3017
+ \begin {example }
3018
+ \begin {codeblock }
3019
+ float fa[17], *afp[17];
3020
+ \end {codeblock }
3021
+ declares an array of \tcode {float} numbers and
3022
+ an array of pointers to \tcode {float} numbers.
3023
+ \end {example }
3024
+
3025
+ \pnum
3030
3026
Any type of the form
3031
- `` \grammarterm {cv-qualifier-seq} array of
3032
- \tcode {N}
3033
- \tcode {T}''
3027
+ `` \grammarterm {cv-qualifier-seq} array of \tcode {N} \tcode {U}''
3034
3028
is adjusted to
3035
- `` array of
3036
- \tcode {N}
3037
- \grammarterm {cv-qualifier-seq}
3038
- \tcode {T}'' ,
3039
- and similarly for
3040
- `` array of unknown bound of
3041
- \tcode {T}'' .
3042
- The optional \grammarterm {attribute-specifier-seq} appertains to the array.
3029
+ `` array of \tcode {N} \grammarterm {cv-qualifier-seq} \tcode {U}'' ,
3030
+ and similarly for `` array of unknown bound of \tcode {U}'' .
3043
3031
\begin {example }
3044
-
3045
3032
\begin {codeblock }
3046
3033
typedef int A[5], AA[2][3];
3047
3034
typedef const A CA; // type is `` array of 5 \tcode {const int}''
3048
3035
typedef const AA CAA; // type is `` array of 2 array of 3 \tcode {const int}''
3049
3036
\end {codeblock }
3050
3037
\end {example }
3051
3038
\begin {note }
3052
- An
3053
- `` array of
3054
- \tcode {N}
3055
- \grammarterm {cv-qualifier-seq}
3056
- \tcode {T}''
3039
+ An `` array of \tcode {N} \grammarterm {cv-qualifier-seq} \tcode {U}''
3057
3040
has cv-qualified type; see~\ref {basic.type.qualifier }.
3058
3041
\end {note }
3059
3042
3060
3043
\pnum
3061
- An array can be constructed from one of the fundamental types
3062
- (except
3063
- \tcode {void}),
3064
- from a pointer,
3065
- from a pointer to member, from a class,
3066
- from an enumeration type,
3067
- or from another array.
3044
+ An object of type `` array of \tcode {N} \tcode {U}'' contains
3045
+ a contiguously allocated non-empty set
3046
+ of \tcode {N} subobjects of type \tcode {U},
3047
+ known as the \defnx {elements}{array!element} of the array,
3048
+ and numbered \tcode {0} to \tcode {N-1}.
3068
3049
3069
3050
\pnum
3070
- \indextext {declarator!multidimensional array}%
3071
- When several `` array of'' specifications are adjacent, a
3072
- multidimensional array
3073
- type is created;
3074
- only the first of
3075
- the constant expressions that specify the bounds
3076
- of the arrays may be omitted.
3077
3051
In addition to declarations in which an incomplete object type is allowed,
3078
3052
an array bound may be omitted in some cases in the declaration of a function
3079
3053
parameter\iref {dcl.fct }.
3080
3054
An array bound may also be omitted
3081
- when the declarator is followed by an
3082
- \grammarterm {initializer}\iref {dcl.init },
3083
- when a declarator for a static data member is followed by a
3084
- \grammarterm {brace-or-equal-initializer}\iref {class.mem },
3085
- or in an explicit type conversion\iref {expr.type.conv }.
3086
- In these cases, the bound is calculated from the number
3055
+ when an object (but not a non-static data member) of array type is initialized
3056
+ and the declarator is followed by an initializer
3057
+ (\ref {dcl.init }, \ref {class.mem }, \ref {expr.type.conv }, \ref {expr.new }).
3087
3058
\indextext {array size!default}%
3088
- of initial elements (say,
3089
- \tcode {N})
3059
+ In these cases, the array bound is calculated
3060
+ from the number of initial elements (say, \tcode {N})
3090
3061
supplied\iref {dcl.init.aggr },
3091
- and the type of the identifier of
3092
- \tcode {D}
3093
- is `` array of
3094
- \tcode {N}
3095
- \tcode {T}'' .
3062
+ and the type of the array is `` array of \tcode {N} \tcode {U}'' .
3063
+
3064
+ \pnum
3096
3065
Furthermore, if there is a preceding declaration of the entity in the same
3097
3066
scope in which the bound was specified, an omitted array bound is taken to
3098
3067
be the same as in that earlier declaration, and similarly for the definition
3099
3068
of a static data member of a class.
3100
-
3101
- \pnum
3102
3069
\begin {example }
3103
3070
\begin {codeblock }
3104
- float fa[17], *afp[17];
3071
+ extern int x[10];
3072
+ struct S {
3073
+ static int y[10];
3074
+ };
3075
+
3076
+ int x[]; // OK: bound is 10
3077
+ int S::y[]; // OK: bound is 10
3078
+
3079
+ void f() {
3080
+ extern int x[];
3081
+ int i = sizeof(x); // error: incomplete object type
3082
+ }
3105
3083
\end {codeblock }
3106
- declares an array of
3107
- \tcode {float}
3108
- numbers and an array of
3109
- pointers to
3110
- \tcode {float}
3111
- numbers.
3112
3084
\end {example }
3113
3085
3114
3086
\pnum
3087
+ \indextext {declarator!multidimensional array}%
3088
+ \begin {note }
3089
+ When several `` array of'' specifications are adjacent,
3090
+ a multidimensional array type is created;
3091
+ only the first of the constant expressions
3092
+ that specify the bounds of the arrays may be omitted.
3115
3093
\begin {example }
3116
3094
\begin {codeblock }
3117
3095
int x3d[3][5][7];
3166
3144
\tcode {x3d}
3167
3145
(an integer).
3168
3146
\end {example }
3169
- \begin {note }
3170
3147
The first subscript in the declaration helps determine
3171
3148
the amount of storage consumed by an array
3172
3149
but plays no other part in subscript calculations.
3173
3150
\end {note }
3174
3151
3175
- \pnum
3176
- \begin {example }
3177
- \begin {codeblock }
3178
- extern int x[10];
3179
- struct S {
3180
- static int y[10];
3181
- };
3182
-
3183
- int x[]; // OK: bound is 10
3184
- int S::y[]; // OK: bound is 10
3185
-
3186
- void f() {
3187
- extern int x[];
3188
- int i = sizeof(x); // error: incomplete object type
3189
- }
3190
- \end {codeblock }
3191
- \end {example }
3192
-
3193
3152
\pnum
3194
3153
\begin {note }
3195
3154
Conversions affecting expressions of array type are described in~\ref {conv.array }.
0 commit comments