Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!gatech!amdcad!tim From: tim@amdcad.AMD.COM (Tim Olson) Newsgroups: comp.lang.c Subject: Re: Was that a Sun bug? Message-ID: <17521@amdcad.AMD.COM> Date: Tue, 14-Jul-87 17:21:38 EDT Article-I.D.: amdcad.17521 Posted: Tue Jul 14 17:21:38 1987 Date-Received: Thu, 16-Jul-87 07:00:29 EDT References: <1429@cci632.UUCP> Reply-To: tim@amdcad.UUCP (Tim Olson) Organization: Advanced Micro Devices, Inc., Sunnyvale, Ca. Lines: 54 Keywords: bug comparison Sun Parallel In article <1429@cci632.UUCP> mark@cci632.UUCP (Mark Stevans) writes: +----- | The following function: | | foo() | { | char c = 2; | | if (c == 2) | printf("c is equal to 2\n"); | | if (c == (2 + 1024)) | printf("c is also equal to 1026\n"); | } | | when compiled with Parallel's C compiler would print both messages. Examining | the assembly language code generated by the compiler revealed that "ccom" | was generating a byte comparison instruction both tests, instead of | extending the character to an int and doing a full-word comparison. | | I know that there is no *real* good reason to compare characters against | integral constants that cannot fit inside char variables. But nevertheless, | I call this a bug. The Parallel "guru" didn't seem interested in looking | at this. He hinted that I should read K&R, which annoyed me considerably. | I responded that this did not violate K&R -- it violated rules so basic | they are not covered in K&R: nowhere in K&R does it say that an integer X | cannot be equal to both Y and Z if Y is not equal to Z. +----- Maybe the "Parallel guru" should read K&R: 6.6 Arithmetic conversions "A great many operators cause conversions and yield result types in a similar way. This pattern will be called the 'usual arithmetic conversions.' First, any operands of type char or short are converted to int..." 7.6 Relational operators "...The usual arithmetic conversions are performed..." 7.7 Equality operators "The == (equal to) and the != (not equal to) operators are exactly analogous to the relational operators..." -- Tim Olson Advanced Micro Devices (tim@amdcad.amd.com)