comp.lang.ada
 help / color / mirror / Atom feed
* Why C is hard to learn - Was: Is it a bug in C compilers?
@ 1991-06-20  3:20 Karl A. Nyberg
  0 siblings, 0 replies; only message in thread
From: Karl A. Nyberg @ 1991-06-20  3:20 UTC (permalink / 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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1991-06-20  3:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-06-20  3:20 Why C is hard to learn - Was: Is it a bug in C compilers? Karl A. Nyberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox