Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!gatech!bloom-beacon!think!ames!oliveb!sun!gorodish!guy
From: guy%gorodish@Sun.COM (Guy Harris)
Newsgroups: comp.lang.c
Subject: Re: STREQ
Message-ID: <23222@sun.uucp>
Date: Fri, 10-Jul-87 18:34:21 EDT
Article-I.D.: sun.23222
Posted: Fri Jul 10 18:34:21 1987
Date-Received: Sun, 12-Jul-87 13:58:45 EDT
References: <8277@utzoo.UUCP> <7312@auspyr.UUCP>
Sender: news@sun.uucp
Lines: 21

> >> >>#define    STREQ(a, b)    (*(a) == *(b) && strcmp((a), (b)) == 0)
> 
> This fine idea must be used with caution.
> 
> Note that strcmp() and its siblings correctly handle the case
> of null pointers....

Anybody who feeds null pointers to "strcmp" or "STREQ" is screwing
up.  Since a null pointer does not point to any object, it is
meaningless to ask what "strcmp" should return; it returns an
indication of whether the string referred to by the first pointer
argument is less than, equal to, or greater than the second string.
Since a null pointer does not refer to ANY string, there is no way to
assign a meaning to a call to "strcmp" that passes a null pointer.
Anything "strcmp" wants to do when passed a NULL pointer, including
crashing the running program, is perfectly legitimate; there are
implementations of "strcmp" and company that do crash when handed
null pointers.
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com