Another rant
Xen
list at xenhideout.nl
Fri Nov 17 19:02:41 UTC 2017
Colin Law schreef op 17-11-2017 18:36:
> On 17 November 2017 at 15:45, Xen <list at xenhideout.nl> wrote:
>> Liam Proven schreef op 17-11-2017 0:18:
>>
>>> Agreed with all of that. It's caused a whole world of problems, too.
>>
>>
>> I just lost an entire day to C because
>>
>> a) I'm a novice
>> b) Older versions of GCC had different behaviour
>
> Was that a change to the c/c++ standard rather than a gcc issue? If
> so then you would have had the same issues on Windows.
No apparently the C standard leaves it as undefined but GCC chooses to
implement it in a certain way OR it is even platform (CPU) specific.
GCC used to allow -1 << 4 but a patch in 2015 now ensures errors when
doing so.
One must now use ~0 << 4 to achieve the same effect if that even works
because I think it doesn't
and you have to use ~0U or something.
I think it even treats 0 as signed, ~0 as -1, and then fails.
But I am confused, << is apparently undefined and >> is defined as sign
extension.
But honestly this only goes to show the quagmire this language is.
My program error probably resulted from me depending on >>
and seeing different behaviour across 2 platforms.
GCC now clearly defines it as arithmetic shift right.
"If E1 has a signed type and a negative value, the resulting value is
implementation-defined." (C89 standard)
It clearly also didn't change in C90.
It also did not change in C11.
https://port70.net/~nsz/c/c11/n1570.html
So no, your allusion is incorrect
Yet the C standard does say that the implementation can be
platform-specific.
More information about the ubuntu-users
mailing list