Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #70019
| 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 | 2019-11-23 12:35 -0800 |
| Organization | None to speak of |
| Message-ID | <lnv9rawctx.fsf@kst-u.example.com> (permalink) |
| References | <qrb80f$9t4$1@dont-email.me> |
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