Re: Question about size and memory layout of a Union.
On Oct 19, 8:16 pm, Justin Spahr-Summers
<Justin.SpahrSumm...@gmail.com> wrote:
> On Oct 19, 7:36 pm, gordonb.e8...@burditt.org (Gordon Burditt) wrote:
>
> > >> There are 32! possible orderings of 32 bits, though only a small number
> > >> of those orderings are actually used. However, I've read that of the 12
> > >> possible orderings of the 4 bytes underlying a 4-byte integer, 8 of them
> > >> are in actual use.
>
> > >ITYM 24 possible orderings. Just like there are 32! possibilities with
> > >32 bits, there are 4! possibilities with 4 bytes. 4! = 24.
>
> > What in the standard prohibits the use of different bit-orderings to
> > represent integers, such that, say, the most significant bit and the
> > least significant bit are in the *same* byte (and next to each other)?
>
> I'm not able to look up whether there is such a clause or not, but it
> doesn't really matter. Bitwise operations are defined in terms of
> arithmetic, and you shouldn't need to know the representation for
> portable code anyhow.
I spoke much too soon. I found a draft of the standard real quick and
realized my mistake. Only bitwise shift operations are defined in
terms of arithmetic, apparently. I don't know how much that changes,
however.
|