Path: csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: NULL as the empty string Date: Tue, 21 Nov 2017 15:28:10 -0800 Organization: None to speak of Lines: 39 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="9437c726f685efabd2d584afa836bd7f"; logging-data="19934"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19q777AtnJ9KsAEFW/Zrwy4" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:dtidU0H+djIEt4qZE5uNvEWgwYI= sha1:6YP0VUtpyjrQewrNkxMbd4txZWw= Xref: csiph.com comp.lang.c:123239 ram@zedat.fu-berlin.de (Stefan Ram) writes: > jacobnavia writes: >>Whaat would happen if we decide to give meaning to NULL? > > One can do so by > > #include > > . > >>strlen would return zero, etc. This way, we would save terabytes of "\0" >>strings since an empty string would not require any storage, since it is >>empty of course! > > An implementation already is free to map all »""« to the same address. > > »It is unspecified whether these arrays are distinct > provided their elements have the appropriate values.« > > 6.4.5p7 Yes, but there's a difference between an empty string and an empty string literal. This: char s[] = ""; creates an empty string. The address of s won't be the same as the address of an empty string literal (unless there's some interesting optimization going on). [...] -- 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"