• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why is UInt32 << 32 a no-op?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why is UInt32 << 32 a no-op?


  • Subject: Re: Why is UInt32 << 32 a no-op?
  • From: Alastair Houghton <email@hidden>
  • Date: Tue, 17 Nov 2009 18:24:15 +0000

On 17 Nov 2009, at 17:15, Jeremy Pereira wrote:

> On 17 Nov 2009, at 16:56, Jens Alfke wrote:
>
>> Surprisingly, the expression "n << 32", where n is a 32-bit integer, is a no-op.

[snip]

>> Any C expert know whether this is in-spec or not?
>
> Not an expert, but from the C99 standard (6.5.7):
>
> "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."
>
> I speculate that the reasoning behind that statement is that some hypothetical architecture might choose to represent a shift of a 32 bit number using a 5 bit field to specify the number of bits to shift.

It isn't necessarily just a 5-bit field (in the instruction) that's a problem.  The shift hardware itself may very well only have a 5-bit input, in which case *even if* the shift value is coming from a register, you'll still get this kind of behaviour.

But you've hit the nail on the head as far as the standard goes.  Shifting a 32-bit value by 32 bits results in an undefined result.

Kind regards,

Alastair.

--
http://alastairs-place.net



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Why is UInt32 << 32 a no-op? (From: Jens Alfke <email@hidden>)
 >Re: Why is UInt32 << 32 a no-op? (From: Jeremy Pereira <email@hidden>)

  • Prev by Date: Re: Why is UInt32 << 32 a no-op?
  • Next by Date: Re: Why is UInt32 << 32 a no-op?
  • Previous by thread: Re: Why is UInt32 << 32 a no-op?
  • Next by thread: Re: Why is UInt32 << 32 a no-op?
  • Index(es):
    • Date
    • Thread