From: karl@grebyn.com (Karl A. Nyberg)
Subject: Why C is hard to learn - Was: Is it a bug in C compilers?
Date: Wed, 19 Jun 91 23:20:09 -0400 [thread overview]
Message-ID: <9106200320.AA00393@grebyn.com> (raw)
[Forwarded from alt.sys.sun (of all places)]
Does C++ inherit (!) this (mis?)feature from C? And we thought the Ada
lawyers had a monopoly on quoting the Language Reference Manual!
-- Karl --
In article <4201@island.COM> rich@island.COM writes:
>luke@research.canon.oz.au (Luke Kendall) writes:
>>A bug in the Sun and GNU C compilers. The following tiny program does
>>not work:
>
>>main()
>>{
>> int i, shift;
>> printf("%x\n", 0x10000 >> 1000);
>> for (shift = 1, i = 0; i < 5; ++i, shift *= 10)
>> printf("%x >> %d = %x\n", 0x10000, shift, 0x10000 >> shift);
>>}
>From The C Programming Language, Second Edition, by Kernighan and Ritchie,
>pg. 206, on the right shift operator:
>
>"The result is undefined if the right operand is negative, or greater than
>or equal to the number of bits in the left expression's type."
>
>>In other words, both compilers are failing to mask the right operand
>>of the shift.
>
>Failing, yes, but then the language definition explicitly states that
>the compiler does not have to handle this case. This is yet another
>reason why C is one of the most efficient high-level languages and hard
>for programmers to master.
reply other threads:[~1991-06-20 3:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox