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: Tue, 15 May 2018 09:09:27 -0700 Organization: None to speak of Lines: 42 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="fd2ef88f3973fbdcdd5cf6f7f328cfd4"; logging-data="9601"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/oeYiEiG1mJXLr4YLL0EA0" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:5WZ7+/OSIy1HkQlZVfl93wUhidQ= sha1:yKfEGJ0VoIFgomCcYxEa+jsUPxw= Xref: csiph.com comp.lang.c:130610 David Brown writes: [...] > I also don't see a big benefit in being able to evaluate &PI - but there > might occasionally be use in passing such fixed values by reference. It > would make a bigger difference if the type were of bigger size, enough > to make pass-by-reference more efficient. > > But what I really don't see is any benefit in /not/ being able to > evaluate &PI. > > (I see a benefit in language or compiler protections against abusing > that &PI pointer.) Do you see any benefit in not being able to apply "&" to an enumeration constant? Or an integer constant? What some of us would like is a way to associate a name with a constant expression of arbitrary scalar type, without defining a macro. Constant expressions don't have addresses. Not being able to apply "&" to such a name is more a matter of conceptual elegance and consistency than of practical need. One (perhaps rather inelegant) solution would be to allow specifying a scalar type for an enum. Currently we can write enum { answer = 42 }; and get exactly the behavior some of us are looking for (but only for type int). If we could write something like: enum : double { pi = 22.0/7.0 }; or even enum : void* { NULL = 0 }; to make pi and NULL constant expressions (with no associated storage, even in the abstract machine), that would provide just the functionality some of us would like. (Using 22.0/7.0 for pi was a joke, in case anyone was going to complain about it.) -- 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"