Bug in ANSI C??

Mark Brader msb at sq.uucp
Sat Feb 20 10:49:54 AEST 1988


The wording in the November 1987 (the second-latest) draft is:

# 4.11.4 Comparison functions
#	The sign of the value returned by the comparison functions is
# determined by the sign of the difference between the values of the
# first pair of characters that differ in the objects
  [ i.e.the strings, in this case ]
# being compared.  If one of the characters has its high-order bit set,
# the sign of the result is implementation-defined.
  ...
# 4.11.4.2 The strcmp function
  ...
# The strcmp function returns an integer greater than, equal to, or
# less than zero, according as the string pointed to by [argument] s1
# is greater than, equal to, or less than the string pointed to be s2.

Thus strcmp ("xy\300", "xy\100") may return a positive or negative
number but not zero.

The last time I read this section, I decided that the words about
"first pair of characters that differ" meant that the same was true
in the case of strcmp ("x\300", "x"); but now I'm not so sure.
That was probably the *intent*, but one could consider it to be
contradicted by the word "strings" in the last quoted sentence, taken
together with the usual notion of lexical ordering.

Mark Brader				"C takes the point of view
SoftQuad Inc., Toronto			 that the programmer is always right"
utzoo!sq!msb, msb at sq.com				-- Michael DeCorte



More information about the Comp.lang.c mailing list