Keith Thompson <
Keith.S.T...@gmail.com> writes:
> Tim Rentsch <
tr.1...@z991.linuxsc.com> writes:
>
>> Keith Thompson <
Keith.S.T...@gmail.com> writes:
>>
>>> "Alf P. Steinbach" <
alf.p.stein...@gmail.com> writes:
>>> [...]
>>>
>>>>> On 29/06/2020 21:49, Chris Vine wrote:
>>>
>>> [...]
>>>
>>>>>> a requirement that, for any type T, sizeof(T[sz]) must be the same as
>>>>>> sizeof(T)*sz
>>>>
>>>> In C++17 this is specified by 8.3.3/2,
>>>>
>>>> "When applied to an array, the result is the total number of bytes in
>>>> the array. This implies that the size of an array of /n/ elements is
>>>> /n/ times the size of an element."
>>>>
>>>> ... where the ?This implies? is normative text, not a note.
>>>
>>> Yes, I had somehow managed to miss that.
>>>
>>> I'm still curious *how* it implies it. The "This implies that ..."
>>> wording seems to indicate that it's a consequence of some normative
>>> requirement elsewhere in the standard. [...]
>>
>> The C++ standard uses but does not define the term "array type".
>
> The C++ standard doesn't define that particular phrase, but it discusses
> array types in 6.9.2 [basic.compound] and 11.3.4 [dcl.array] (references
> are to C++17).
I hadn't noticed the passage in 6.9.2; thank you for pointing it
out.
The references to array type in 11.3.4 are ones I had seen as part
of my review prior to the earlier posting. These passages do refer
to "array type"; I don't think either one is meant to define the
term, only to refer to it.
>> The C++ standard includes the C standard as a normative reference
>> (1 p2, "C++ is a general purpose programming language based on
>> the C programming language as described in ISO/IEC 9899:2011
>> Programming languages - C", and also 2 p1.3).
>>
>> The C standard defines the term "array type" - 6.2.5 p20, first
>> subitem: "An array type describes a contiguously allocated
>> nonempty set of objects with a particular member object type,
>> called the element type" (and "array type" is italicized,
>> indicating a definition).
>
> C++17 11.3.4: "An object of array type contains a contiguously
> allocated non-empty set of N subobjects of type T."
That sentence states a property of objects (of array type) but
doesn't define the term "array type" itself. For that matter it
isn't a definition of array-type objects either: it says they
/contain/ "a contiguously allocated non-empty set of N subobjects"
but doesn't say what else might be true (or not) about them.
>> An array type under the C definition has no padding.
>>
>> So unless there is a conflicting statement somewhere in the C++
>> standard, it seems reasonable to conclude arrays in C++ cannot
>> have padding.
>
> The C++ standard includes (most of) the C library by reference,
> but as I understand it it provides its own descriptions of
> everything in the core language.
The second paragraph of section 1 (intro.scope) says this:
C++ is a general purpose programming language based on the C
programming language as described in ISO/IEC 9899:2011
Programming languages -- C (hereinafter referred to as the C
standard). In addition to the facilities provided by C, C++
provides additional data types, classes, templates,
exceptions, namespaces, operator overloading, function name
overloading, references, free store management operators,
and additional library facilities.
> I'm not aware of anything in the C++ core language that's defined by
> the C standard. At the very least, *most* of the C++ core language
> is defined directly by the C++ standard. If there are omissions, my
> first assumption would be that they're unintentional, not that the C
> core language definition fills in the gaps.
That assumption may very well be right. I do think though that the
existing wording can be read either way. The quoted 1 p2 does say
"In addition to the facilities /provided/ by C" (my emphasis). If
we can agree that either interpretation is at least plausible then
I am happy to leave it at that.
> It's not 100% clear to me that either the C or C++ discussion of array
> types completely excludes the possibility of padding at the end.
As far as C goes, I consider it a settled question. My reasoning
is much the same as what James Kuyper said in his followups to
Alf and Manfred: the definition of "array type" doesn't consider
the possibility of anything other than a contiguously allocated
set of objects, and other derived types that do admit padding
all mention padding explicitly.
Also, if it helps, I asked about this question many years ago in
comp.lang.c (or maybe comp.std.c?). There was a response from Doug
Gwyn, who said array types cannot have padding (or words to that
effect). I'm sorry I can't be more specific; it was a long time
ago, and the groups history seems to have fallen off the face of
the earth. IIRC 'sizeof (T[N]) == N * sizeof (T)' was included
in the subject line. If some ambitious web searcher is able to
find something about those it would be nice to hear about it.