Soviet_Mario <Sovie...@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)
ks...@mib.org <
http://www.ghoti.net/~kst>
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */