Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: [QT creator on "nix"] - getting a strict 8 bit (1 byte) array with no padding
Date: Thu, 28 Nov 2019 12:51:23 -0800
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <86pnhbafn8.fsf@linuxsc.com>
References:
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="dce185ee50ea005ee4a34884a21fb89a"; logging-data="26629"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+k61l5XqObBxDwUF8neX+T2d0PeE+HU0E="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:3BjS0CbKPfCfr/KLzHxm6lRwXh8= sha1:gwK1Ir3vCYevxXCmxV1+kdpFfW8=
Xref: csiph.com comp.lang.c++:70092
James Kuyper writes:
> On 11/22/19 10:49 AM, James Kuyper wrote:
>
>> On 11/22/19 4:10 AM, David Brown wrote:
>>
>>> On 22/11/2019 09:37, Keith Thompson wrote:
>>
>> ...
>>
>>>> Or an array wrapped in a struct to allow assignment. (An array of 4
>>>> uint8_t elements is guaranteed to be 32 bits, but a struct containing
>>>> such an array is not -- but it's a nearly safe assumption that there
>>>> will be no padding between the elements or at the end.)
>>>
>>> While it is true in theory that a struct can have extra padding at the
>>> end (beyond what is needed for an array of the struct to have proper
>>> alignment for all members), are there any compilers that have done so in
>>> practice?
>>
>> I can't name names, but my understanding is that there have been (and
>> might still be) implementations where all struct types have the same
>> alignment requirement as the most strictly aligned type supported by
>> that implementation. If that alignment requirement is greater than the
>> requirements of any of the member types, that will sometimes require
>> padding at the end of the struct.
>
> I said that wrong. Unless all members of the struct have the maximum
> alignment requirement, it's possible that such an implementation would
> have to put padding at the end.
Don't you mean, unless the last member of a struct has the
maximum alignment requirement, it's possible such an
implementation would have to put padding at the end.