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 10:24:04 -0700 Organization: None to speak of Lines: 36 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="23646"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/AknG9ED0t/ozYfPE79QES" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:Dufp2b0BTCrg6p4NQ62Ls0kThUw= sha1:ARE2KVFM8zPm+INg+cpVOIj92RU= Xref: csiph.com comp.lang.c:112601 David Brown writes: [...] > Should (x ? 0 : 0) be considered the int constant 0, the null pointer > constant, or should the decision be left to constraint fitting on the > rest of the expression (in this case, the assignment)? (x ? 0 : 0) is a constant expression if and only if x is a constant expression. Given: int x = 42; (x ? 0 : 0); we can determine that the expression is of type int with the value 0, but it's not a constant expression. Consider the case where x is volatile, so evaluating it has side effects. Or consider replacing x by a function call. The definition of a constan expression does not distinguish between non-constant subexpressions with side effects and non-constant subexpressions without side effects. The definition of "constant expression" isn't intended to cover all cases where the result of an expression *can* be determined at compile time. It's intended to be reasonably simple, so that all compilers can be required to implement it correctly. There are cases where an expression whose value *could* be determined at compile time are not treated as constant expressions, but that's not much of an inconvenience in practice. [...] -- 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"