Sujet : Re: relearning C: why does an in-place change to a char* segfault?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 28. Sep 2024, 21:42:31
Autres entêtes
Organisation : None to speak of
Message-ID : <875xqfse6g.fsf@nosuchdomain.example.com>
References : 1 2
User-Agent : Gnus/5.13 (Gnus v5.13)
Phillip Frabott <
nntp@fulltermprivacy.com> writes:
In reply to "Janis Papanagnou" who wrote the following:
[...]
I also think (for various reasons) that "constants" is not a good
term. (Personally I like terms like the Algol 68 term, that seems
to "operate" on another [more conceptual] abstraction level.)
But you'll certainly have to expect a lot of anger if the terminology
of some standards documents get changed from one version to another.
>
The only gripe I would have if we synonymized constants and literals
is that not every const is initialized with a literal. There have been
times where I have initialized a const from the value of a variable. I
don't think that const and literals are the same thing because of
this.
Though the word "const" is obviously derived from the English word
"constant", in C "const" and "constant" are very different things.
The "const" keyword really means "read-only" (and perhaps would have
been clearer if it had been spelled "readonly").
A "constant" is what some languages call a "literal", and a "constant
expression" is an expression that can be evaluated at compile time.
For example, this:
const int r = rand();
is perfectly valid.
Incidentally, the N3301 draft of the C2Y standard has this change
applied to it:
Syntax
constant:
integer-literal
floating-literal
enumeration-constant
character-literal
predefined-constant
The predefined constants are false, true, and nullptr.
(I find it a bit odd that enumeration and predefined constants are still
called constants, not literals.)
Compare C17:
Syntax
constant:
integer-constant
floating-constant
enumeration-constant
character-constant
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3301.pdf(open-std.org seems to be down at the moment.)
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */