Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Recasting data as long ints and chars Date: Wed, 29 Nov 2017 17:01:53 -0800 Organization: None to speak of Lines: 34 Message-ID: References: <87efopstrv.fsf@bsb.me.uk> <87fu90mw6q.fsf@bsb.me.uk> <87d143k9e1.fsf@bsb.me.uk> <87efohsxin.fsf@bsb.me.uk> <87bmjklh7u.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="643b35198f06d57da8186297cf5a7622"; logging-data="8242"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+coCVMlgKtM56JDqIAcvVT" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:MucpVe0Q5qFurOPYC0WHrRg1OJA= sha1:hq5IQgPBZ9kRbZIBKRFIgKdJS7E= Xref: csiph.com comp.lang.c:123630 Ben Bacarisse writes: > Spiros Bousbouras writes: >> On Wed, 29 Nov 2017 01:07:28 +0000 >> Ben Bacarisse wrote: >>> unsigned nb = 0; >>> unsigned U_ORDER = 0; >>> >>> and loop setting >>> >>> (U_ORDER << CHAR_BIT) | nb++ >> >> If sizeof(unsigned) == 1 then U_ORDER << CHAR_BIT >> is undefined behaviour. > > Why? Because CHAR_BIT (which would have to be at least 16) would be equal to the width of the left operand. N1570 6.5.7p3: The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand. If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined > But that's a side issue. [snip] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"