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: Sun, 18 Jun 2017 13:38:59 -0700 Organization: None to speak of Lines: 50 Message-ID: References: <87bmpl40k4.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="1d5a24d016722a50a74735015b7fb40e"; logging-data="23998"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mkqnaj1kYQaXYnbep6z0m" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:KPPWoRaVIfE8c69fhsqGvS7Kcy4= sha1:wJXOPFicPTr4KJWW6OQPMSIxFiI= Xref: csiph.com comp.lang.c:112493 bartc writes: > On 18/06/2017 19:23, Ben Bacarisse wrote: >> bartc writes: >>> int a, b; >>> int *p; >>> >>> p = 0; // (1) >>> p = (a, b, 0); // (2) >>> p = (a ? 0 : 0); // (3) >>> } >>> >>> AIUI, the 0's should all be null pointer constants in these contexts. >> >> Apart from some idea that it should be so, why do you think that? > > Because usually, x=y can be written as x=(a,b,y), or x=a?y:y, and an > assignment from y to x still takes place (subject to side-effects from > evaluating a and b). To expand on what I wrote previously, given int *p; p = (a, b, 0); the constant 0 *is* a null pointer constant -- but the fact that it's a null pointer constant turns out not to be relevant. It's only relevant when the null pointer constant is converted (implicitly or explicitly) to a null pointer type. An implicit conversion occurs, for example, when an null pointer constant is the right operand of an assignment operator whose left operand is of pointer type. Here, the null pointer constant is the right operand of a comma operator, which does not cause a conversion to a pointer type. Both `a, b, 0` and `(a, b, 0)` are expressions that happen to contain a null pointer constant. That doesn't make them a null pointer constants themselves. (A largely irrelevant aside: N1570 6.5.1p5, which describes parenthesized expressions, neglects to say that a parenthesized null pointer constant is an null pointer constant. The intent, that a parenthesized null pointer constant *is* an null pointer constant, seems to be clear enough that I've never seen a compiler that doesn't make that assumption. This is a minor wording glitch in the standard, not a serious issue.) -- 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"