From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.5 required=3.0 tests=BAYES_05 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: Wed, 19 Jun 91 23:20:09 -0400 From: karl@grebyn.com (Karl A. Nyberg) Subject: Why C is hard to learn - Was: Is it a bug in C compilers? Message-ID: <9106200320.AA00393@grebyn.com> List-Id: [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.