Re: gcc and bitwise right shift
Re: gcc and bitwise right shift
- Subject: Re: gcc and bitwise right shift
- From: Clark Cox <email@hidden>
- Date: Thu, 19 Mar 2009 08:17:03 -0700
On Thu, Mar 19, 2009 at 4:03 AM, Jeremy Pereira <email@hidden> wrote:
>
> On 18 Mar 2009, at 15:22, Hamish Allan wrote:
>
>> On Wed, Mar 18, 2009 at 3:10 PM, Jeremy Pereira <email@hidden> wrote:
>>
>>> 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.
>>
>> In the context of someone querying a different in behaviour between
>> gcc and VC++, you referred to "the C compiler". In this context, I'm
>> sure John would have expected you to refer specifically to "gcc" if
>> that's what you meant, so I think his interpretation is perfectly
>> reasonable.
>
> The Visual Studio C compiler* behaves in the same way. I think it is
> reasonable to assume I was talking about general compiler behaviour rather
> than C99 standard specification, especially as I used the phrase "C
> compiler" not "C standard".
The "C standard" defines what a "C compiler" is. Any compiler that
does not adhere to the C standard is not a C compiler. Hence, it is
reasonable to look to the standard when you want to talk about the
general behavior of C compilers.
The key takeaway point: Don't shift signed, negative integers if you
care about whether 1's or 0's will be shifted in from the left, as
some compilers will give you 1's and some compilers will give you 0's.
Cast to an equivalently sized unsigned type to do your shifting, and
you'll be safe on any C compiler out there.
--
Clark S. Cox III
email@hidden
_______________________________________________
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