Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uflorida!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: NULL as a string terminator Message-ID: <13484@smoke.BRL.MIL> Date: 5 Aug 90 02:20:26 GMT References: <9220003@hpldsla.sid.hp.com> <707@mtune.ATT.COM> <26593@nigel.ee.udel.edu> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 12 In article <26593@nigel.ee.udel.edu> gdtltr@freezer.it.udel.edu (Gary Duzan) writes: >=> char command[15]; >=> command[strlen(command)-1]=NULL; /* chop off the \n */ > Pardon me for reopening the NULL discussion, but won't this give a warning >if NULL is #defined (void *) 0? If it doesn't, should it? Assigning a pointer >to a char is certainly a questionable thing to do. You're correct; the example code would happen to work with the traditional definition of NULL as plain 0, but not if it's defined as ((void*)0). In general it is a mistake to use the NULL macro for any purpose other than a stand-in for a null pointer constant. In the example code, either 0 or '\0' would be a reasonable replacement for NULL.