Variable structure size -- ANSI ?
Will Crowder
willcr at bud.sos.ivy.isc.com
Sat Apr 13 09:42:58 AEST 1991
In article <6246 at male.EBay.Sun.COM>, harry at matilda.uk.sun.com (Harry
Protoolis - Sun EHQ) writes:
> |> Michael N Johnston writes:
> |> ]>struct foo {
> |> ]>unsigned short recsize;
> |> ]>unsigned short num;
> |> ]>char info [24];
> |> ]>byte flags;
> |> ]>char filename[1]
> |> ]>};
> |> ]>Where, foo.filename is a placeholder for a variable length string.
> |>
>
> A question really, does the standard *guarantee* the physical order of
> structure elements ? I looked in K&R 2 and couldn't find anything.
The ANSI standard guarantees that elements of a structure will be allocated
in the order declared. However, there may be any amount of padding between
structure elements. But yes, for
struct foo {
int a;
int b;
};
&foo.b is guaranteed to be greater then &foo.a. Also, &foo is guaranteed
to be equal to &foo.a.
|> Harry
|> ---
Hope this helps,
Will
--------------------------------------------------------------------------------
Will Crowder, MTS | "An optimist sees a glass that's half full. A
(willcr at ivy.isc.com) | pessimist sees a glass that's half empty. An
INTERACTIVE Systems Corp. | engineer sees a glass that's twice as big as
| it needs to be!" -- unknown (at least, by me)
More information about the Comp.lang.c
mailing list