• 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
Why is UInt32 << 32 a no-op?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why is UInt32 << 32 a no-op?


  • Subject: Why is UInt32 << 32 a no-op?
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 17 Nov 2009 08:56:08 -0800

Surprisingly, the expression "n << 32", where n is a 32-bit integer, is a no-op. I would expect it to result in zero for all values of n.

	UInt32 n = (UInt32)-1L;
	int shift = 32;
	n = n << shift;
	assert(n==0);		// fails; n is actually unchanged

This is breaking some code of mine that masks out the upper b bits of a number, where 0≤b≤8; it fails when b==0 because the mask it generates is all 1s instead of all 0s. I'm going to have to add a special case.

Any C expert know whether this is in-spec or not?

—Jens _______________________________________________
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

  • Follow-Ups:
    • Re: Why is UInt32 << 32 a no-op?
      • From: "Eric A. Borisch" <email@hidden>
    • Re: Why is UInt32 << 32 a no-op?
      • From: Jocelyn Houle <email@hidden>
    • Re: Why is UInt32 << 32 a no-op?
      • From: email@hidden (Christian Demmer)
    • Re: Why is UInt32 << 32 a no-op?
      • From: Jeremy Pereira <email@hidden>
  • Prev by Date: Re: How to tell GCC where to find source code?
  • Next by Date: Re: Why is UInt32 << 32 a no-op?
  • Previous by thread: Re: SPAM-LOW: Re: How to tell GCC where to find source code?
  • Next by thread: Re: Why is UInt32 << 32 a no-op?
  • Index(es):
    • Date
    • Thread