[comp.sys.ibm.pc] Bug in ANSI C??

dick@slvblc.UUCP (Dick Flanagan) (02/14/88)

In article <2118@bsu-cs.UUCP> dhesi@bsu-cs.UUCP (Rahul Dhesi) writes:
>In article <241@oracle.UUCP> rbradbur@oracle.UUCP (Robert Bradbury) writes:
>>On another note; does everyone realize that the current standard allows
>>the results of the str/memcmp() function to be implementation defined
>>if the characters being compared have the high-bit set?
>
>You mean that I can have two identical strings with high bits set, and
>strcmp() could return something other than 0?

No.  Equal is equal.

>Or does the problem lie only in deciding lexical order?

The problem lies in that the developer of the run-time routines is free
to decide that strcmp() is comparing *signed* eight-bit numbers, so that
any character with the high-bit set is considered to be *lower* than any
character with the high-bit off.  This would mean that the non-equal
returns could differ between one compiler and another.

>While we're on the subject, just what is the meaning of "implementation-
>defined"?

"Left to the discretion of the compiler run-time routine developer."

Dick

--
Dick Flanagan, W6OLD                         GEnie: FLANAGAN
UUCP: ...!ucbvax!ucscc!slvblc!dick           Voice: +1 408 336 3481
INTERNET: slvblc!dick@ucscc.UCSC.EDU         LORAN: N037 05.5 W122 05.2
USPO: PO Box 155, Ben Lomond, CA 95005

dhesi@bsu-cs.UUCP (Rahul Dhesi) (02/15/88)

In article <241@oracle.UUCP> rbradbur@oracle.UUCP (Robert Bradbury) writes:
>On another note; does everyone realize that the current standard allows
>the results of the str/memcmp() function to be implementation defined
>if the characters being compared have the high-bit set?

You mean that I can have two identical strings with high bits set, and
strcmp() could return something other than 0?  This would be truly a
serious flaw in the standard.

Or does the problem lie only in deciding lexical order?  That's not so
bad--I wouldn't trust the standard library in that case anyway, since
we all have our own opinions about what lexical order is correct.

While we're on the subject, just what is the meaning of "implementation-
defined"?  E.g., "Oh, by the way, I would avoid comparing strings
with high bits set, since the result is implementation-defined.  On
this particular system the result is that all disk packs are erased and
the system halts."
-- 
Rahul Dhesi         UUCP:  <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!dhesi