[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#285396: [ARM] wide chars don't work

On Tue, 2005-01-11 at 22:36 +0100, Thiemo Seufer wrote:
> Jim Gettys wrote:
> [snip]
> > > Strictly speaking, the ARM impementation of gcc is allowed to behave
> > > that way by the C standard. Not exercising this degree of freedom may
> > > be desireable to keep broken code working, but I'll leave it to the
> > > ARM people to weigh the tradeoff.
> > 
> > Are you sure?  Remember it is an array of such structures, not a
> > structure embedded in another structure or on its own....
> >
> > If you have a pointer to the language in the standard, it might
> > elucidate the situation a bit.
> >From a slightly outdated C99 draft, about the definition of arrays
> and structures:
>        [#19] Any number of derived types can  be  constructed  from
>        the object, function, and incomplete types, as follows:
>          -- An   array  type  describes  a  contiguously  allocated
>             nonempty set of objects with a particular member object
>             type, called the  element  type.31)   Array  types  are
>             characterized  by  their element type and by the number
>             of elements in the array.  An array type is said to  be
>             derived  from its element type, and if its element type
>             is T, the array type is  sometimes  called  ``array  of
>             T''.  The construction of an array type from an element
>             type is called ``array type derivation''.
>          -- A structure type  describes  a  sequentially  allocated
>             nonempty   set  of  member  objects  (and,  in  certain
>             circumstances, an incomplete array), each of which  has
>             an  optionally  specified  name  and  possibly distinct
>             type.

Seems pretty silent on whether an array of structures are packed or not.

> About the sizeof operator:
>        [#3] When applied to an operand that has type char, unsigned
>        char,  or  signed char, (or a qualified version thereof) the
>        result is 1.  When applied to  an  operand  that  has  array
>        type,  the  result  is  the  total  number  of  bytes in the
>        array.73)   When applied to an operand that has structure or
>        union type, the result is the total number of bytes in  such
>        an object, including internal and trailing padding.
> This means internal and trailing padding is part of the object, and
> each member object of an aggregation has it. (It would be plain insane
> to define sizeof(struct ...) in dependence of its context.) This, BTW,
> is the reason why the canonical way to compute the number of elements
> in an array is:
>       sizeof array / sizeof array[0]

Note that this works consistently whether the object is padded in size
or or not, in this case, since the array would double in size even as
the individual structure size doubled.
				- Jim

Reply to: