Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: NULL as the empty string Date: Fri, 08 Dec 2017 11:11:58 -0800 Organization: None to speak of Lines: 37 Message-ID: References: <0f96b837-7b9a-435f-81ec-8bbc8d2f928b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="1340e3a39e3bc56856ea47c41c4689d1"; logging-data="16355"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fthuGyjKYcAs65Dq9LuzQ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:M6N0qYy/sYDDceqwZFjr3HAcUD0= sha1:rBrJ8atFTT485XIMBHSBx/Oid5c= Xref: csiph.com comp.lang.c:124020 John Bode writes: > On Tuesday, November 21, 2017 at 5:16:29 PM UTC-6, Keith Thompson wrote: >> jacobnavia writes: >> > Whaat would happen if we decide to give meaning to NULL? >> >> NULL (more precisely a null pointer) has a meaning. It's a pointer >> value that doesn't point to anything. > > I think I get what Jacob is getting at - instead of NULL being a macro > that expands to a 0, have it be a special keyword with special, > context-dependent semantics. That is, a call against strlen or strcmp > with NULL would be interpreted differently by the compiler, which > would emit code that immediately returned a 0 or false result, without > having to actually evaluate anything, or store an actual empty string > or pointer to an empty string. That wasn't the impression I got at all. I thought jacob was advocating giving a null pointer value a special meaning, so that either strlen(NULL) or strlen(0) or char *ptr = 0; strlen(ptr) would return 0 (rather than having undefined behavior, as it currently does). I didn't think he was talking about giving the NULL macro a special meaning distinct from being a null pointer constant. jacob, would you care to comment? [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"