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: Sun, 13 May 2018 13:20:48 -0700 Organization: None to speak of Lines: 35 Message-ID: References: <11edbfd7-461d-4579-8ac7-a9e84a6b7630@googlegroups.com> <7b110d3e-ddb5-42a0-af99-aa5b0cb30832@googlegroups.com> <13efc313-d10c-4357-9aa7-6fa55b09d948@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="de03f435d476b908b3153305d9b0869d"; logging-data="1407"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4PCNZmx07n3SueCc7U33E" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:2Anjb7spjYWIBmrmfWBsXS43WMI= sha1:5s4WXLCBZHEp7S4sLoMiSplXKpM= Xref: csiph.com comp.lang.c:130511 David Brown writes: [...] > The only kind of constants in C and C++ that might unnecessarily use > storage are if you have a "const" that is declared with external linkage > (for C, that is the default if you don't use "static" - for C++, you > need an explicit "extern" declaration) but don't actually need it > externally. The answer here, of course, is to write your program > correctly - if a "const" is only used in the one translation file, make > it "static". [...] You are conflating "const" and "constant". They mean two *very* different things in C. Defining an object with "const" never makes its name a constant expression. A *constant* in C is a lexical element, either an integer-constant, a floating-constant, an enumeration-constant, or a character-constant. A *constant expression* is an expression that can, and in some contexts must, be evaluated at compile time. Neither of these has anything to do with the "const" keyword, which means "read-only". (Attempting to modify a const-qualified object after its initialization is a constraint violation.) As I've said before, I'd like to see a feature in C that permits creating a name for a specified constant value of a specified type, making that name a constant expression. I would prefer not to use the "const" keyword for such a feature. (C++ already does so to some extent, and consistency with C++ is generally a good thing, all else being equal.) -- 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"