NULL as a string terminator

Rich Skrenta skrenta at blekko.UUCP
Sun Aug 12 01:18:00 AEST 1990


robert at cs.arizona.edu (Robert J. Drabek) writes:

>>> #define  EOS  '\0'

> I see the difference as one between
> using an object and using a name for the object.  My personal feeling is
> that it is more polite to use the name.

> '\0' has uses and interpretations other than "end-of-
> string".  So when I see EOS I know for certain what I meant.  When I see
> '\0' there is the chance that some other interpretation or use is meant.

In many cases the object itself becomes familiar enough that it's
instantly recognized.  '\0' is one such object.  If I saw in your
code

	*p = EOS;

I'd have to run off to your .h files to find the definition of EOS.
*You* like your non-standard name for '\0', but no one else will
know what it means, and it's unlikely that it will ever be a Big Win
for you (like if we start terminating strings with ^A or something).

Other cases occur where someone makes #defines for error strings
that are used only once:

#define	FOO_BAR_ERROR	"foo bar error"
#define UNDEF_BAZ_ERR	"undef baz err"

I cringe when I come across code like this.  Needlessly removing objects
a level is distracting and gains nothing.

Rich
-- 
skrenta at blekko.commodore.com



More information about the Comp.lang.c mailing list