Skip site navigation (1)Skip section navigation (2)
Date:      14 Sep 1996 17:13:30 -0500
From:      Zach Heilig <zach@blizzard.gaffaneys.com>
To:        Wolfram Schneider <wosch@cs.tu-berlin.de>
Cc:        current@FreeBSD.org
Subject:   Re: str*cmp
Message-ID:  <87d8zoiw39.fsf@freebsd.gaffaneys.com>
In-Reply-To: Wolfram Schneider's message of Sat, 14 Sep 1996 21:43:43 %2B0200
References:  <199609141943.VAA02898@campa.panke.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Wolfram Schneider <wosch@cs.tu-berlin.de> writes:

> src/lib/libc/string/strcmp.c
> int
> strcmp(s1, s2)
> 	register const char *s1, *s2;
> {
> 	while (*s1 == *s2++)
> 		if (*s1++ == 0)
>                     ^^^^^^^^^^
> 		    should be (*s1++ == '\0')

Actually, this is a style issue.  '\0' is an 'int' with the value
zero, exacly like 0 is an 'int' with the value zero.  If you look in
the standard, you will note that '\<octal>' (or '\x<hex>') is a
integer with the literal value of whatever '<octal>' (or <hex>) is.
'\0' is simply an octal integer constant with the value 0 (made up to
LOOK like a character constant).

C++ is a bit different because '\0' is really a 'char' (still 0
valued), but since both languages do type conversions as necessary,
there is no problems caused by that bit of code.

-- 
Zach Heilig (zach@blizzard.gaffaneys.com) | ALL unsolicited commercial email
Support bacteria -- it's the              | is unwelcome.  I avoid dealing
only culture some people have!            | with companies that email ads.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87d8zoiw39.fsf>