• 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: gcc and bitwise right shift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gcc and bitwise right shift


  • Subject: Re: gcc and bitwise right shift
  • From: Jeremy Pereira <email@hidden>
  • Date: Wed, 18 Mar 2009 15:10:57 +0000


On 18 Mar 2009, at 14:32, John Engelhart wrote:

Quoth the C99 standard
(http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf):

6.5.7 Bitwise shift operators

point 4: The result of E1 << E2 is E1 left-shifted E2 bit positions;
vacated bits are filled with zeros. If E1 has an unsigned type, the
value of the result is E1 * 2^E2, reduced modulo one more than the
maximum value representable in the result type. If E1 has a signed
type and nonnegative value, and E1 * 2^E2 is representable in the
result type, then that is the resulting value; otherwise, the behavior
is undefined.

point 5: The result of E1 >> E2 is E1 right-shifted E2 bit positions.
If E1 has an unsigned type or if E1 has a signed type and a
nonnegative value, the value of the result is the integral part of the
quotient of E1 / 2^E2. If E1 has a signed type and a negative value,
the resulting value is implementation-defined.

So, no, the standard does not mandate arithmetic right shifts (i.e., a
signed type with a negative value has its vacated bits filled with
ones, preserving the sign of the value).

Sorry, but could you point out to me where I claimed what the C99 standard mandates? I said what the compiler *does* and this is an observation based on checking the actual output of gcc.


I have personally have never come across a C compiler that doesn't sign extend a negative value when right shifting and would have regarded not sign extending of negative signed numbers as a bug had you not brought section 6.5.7 to my attention.







_______________________________________________ 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: gcc and bitwise right shift
      • From: Hamish Allan <email@hidden>
References: 
 >gcc and bitwise right shift (From: Thierry Faucounau <email@hidden>)
 >Re: gcc and bitwise right shift (From: Jeremy Pereira <email@hidden>)
 >Re: gcc and bitwise right shift (From: John Engelhart <email@hidden>)

  • Prev by Date: Re: private dylib
  • Next by Date: Re: gcc and bitwise right shift
  • Previous by thread: Re: gcc and bitwise right shift
  • Next by thread: Re: gcc and bitwise right shift
  • Index(es):
    • Date
    • Thread