Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #70019
| Path | csiph.com!weretis.net!feeder6.news.weretis.net!feeder7.news.weretis.net!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: [QT creator on "nix"] - "outer" padding within arrays of structures - was getting a strict 8 bit (1 byte) array with no padding |
| Date | Sat, 23 Nov 2019 12:35:22 -0800 |
| Organization | None to speak of |
| Lines | 51 |
| Message-ID | <lnv9rawctx.fsf@kst-u.example.com> (permalink) |
| References | <qrb80f$9t4$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | reader02.eternal-september.org; posting-host="dfad491d1778b0c95e43bf538d0f4f21"; logging-data="609"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kmKJ5iVEkv/4RfvsIvXKu" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:pTRV6re5gTMkyXpHY9tv7QpUrxs= sha1:qb4sAf2qhcySJmGLxQWw9LeT0R4= |
| Xref | csiph.com comp.lang.c++:70019 |
Show key headers only | View raw
Soviet_Mario <SovietMario@CCCP.MIR> writes:
> I have realized I don't know an aspect of padding vs packing
> management.
>
> In the other thread I have been explained of the aspects of
> padding/packing INSIDE a given structure/class/union and
> similar.
>
> But now I realize I know nothing for sure about packing in
> between different element within arrays of such
> structure/class/union and similar.
Packing for arrays is not a thing.
Every object type has a constant size, which you can query using sizeof.
Each element of an array is allocated the size of the element's type.
For example, given:
some_type arr[N];
it's guaranteed that sizeof (arr) == N * sizeof (some_type). (We can
use that to determine the number of elements in an array: sizeof arr /
sizeof arr[0]).
If a non-standard #pragma pack has been applied to some_type itself,
that might change the value of sizeof (some_type), but it does not
change the relationship between sizeof (some_type) and sizeof
(some_type[N]).
The size of any type is a multiple of its alignment, which is what
makes arrays possible.
If some_type is
struct some_type {
long big;
char small;
};
then there is likely to be padding after small, precisely so that in an
array of some_type elements each big sub-element is correctly aligned.
The padding is within the structure. There is no padding between array
elements.
[...]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
[QT creator on "nix"] - "outer" padding within arrays of structures - was getting a strict 8 bit (1 byte) array with no padding Soviet_Mario <SovietMario@CCCP.MIR> - 2019-11-23 13:17 +0100 Re: [QT creator on "nix"] - "outer" padding within arrays of structures - was getting a strict 8 bit (1 byte) array with no padding Keith Thompson <kst-u@mib.org> - 2019-11-23 12:35 -0800
csiph-web