Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Null pointer constant Date: Mon, 19 Jun 2017 12:08:31 -0700 Organization: None to speak of Lines: 50 Message-ID: References: <9zM1B.193976$KK7.183000@fx12.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="6cbb5d51c319bdfdc6c4f737cfea8267"; logging-data="7076"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/POTmc4MNBJNxmKF8Ks5iw" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:QuDpxmt7fpfyaFazqKuKm6riOhg= sha1:6fDWog1IMm0oxRS79QAnbzKKmH8= Xref: csiph.com comp.lang.c:112611 David Brown writes: > On 19/06/17 14:05, bartc wrote: [...] >> (a,b,0) can't be an integer constant expression, even if a and b are >> constants, because the language considers that nonsensical. (a,b,0) isn't an integer constant expression because the language says it isn't. The standard expresses no opinion on how sensible it would be. (I wouldn't have any particular problem if the language permitted comma operators in constant expressions, but forbidding them isn't a problem either.) > True. I suspect that is because the comma operator has a sequence > point, and it would not make sense to have a sequence point in a > constant expression. A conditional expression has a sequence point between the evaluation of the first operand and the evaluation of the second or third operand. I think it's permitted because it can be useful in some cases, particularly in macro expansions. [...] > No, the language does not like it because the sequence points spoil the > special nature of the a pointer constant - there needs to be some rules > to say when 0 is an int, and when it is a null pointer constant. As I've said elsethread, 0 is an expression of type int *and* a null pointer constant. > You can write: > > p = (a, b, (void*) 0); > > You can also write: > > p = (a, b, NULL); > > That is one of the purposes of having the NULL macro - it is /always/ a > null pointer constant. So is 0. Indeed NULL can be #defined simply as 0. [...] -- 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"