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: C++ features for C Date: Fri, 11 May 2018 15:38:58 -0700 Organization: None to speak of Lines: 40 Message-ID: References: <11edbfd7-461d-4579-8ac7-a9e84a6b7630@googlegroups.com> <7b110d3e-ddb5-42a0-af99-aa5b0cb30832@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="6687adca56c220c20b4c449de731b175"; logging-data="27306"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198SeNGDMtmyiT8klKcxva8" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:zMh4nesRGtflaDs0oWncaQm38sk= sha1:QXkPWNPksfgPiUloquqHMRvLIGc= Xref: csiph.com comp.lang.c:130432 Thiago Adams writes: > On Friday, May 11, 2018 at 4:59:34 PM UTC-3, Ian Collins wrote: [...] >> You overlooked the potentially most useful feature: real constants and >> constant expressions. > > Do you mean? > > constexpr double PI2 = 3.141592653589793; > > I don't like because of this: > > int main() { > constexpr double PI2 = 3.141592653589793; > const double *PI = &PI2; > > printf("%p\n", PI); > return 0; > } > > Why it has address? Apparently the `constexpr double ...` declaration defines an object that, like any object, has an address -- and ensures that the name of that object is a constant expression. (I haven't checked the C++ standard on this point so I'm not certain of the details.) Presumably if you don't refer to the address of PI2, the compiler could choose not to allocate storage for it. I can see the point of wanting a construct that creates a constant value (as `enum { answer = 42 };` does for constants of type int). But what problem does the fact that PI2 has an address actually cause? -- 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"