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 : 16. Aug 2024, 00:27:29
Autres entêtes
Organisation : None to speak of
Message-ID : <8734n5fjtq.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Gnus/5.13 (Gnus v5.13)
Tim Rentsch <
tr.17687@z991.linuxsc.com> writes:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
>
Just as 1 is an integer literal whose value cannot be modified,
[...]
>
The C language doesn't have integer literals. C has string
literals, and compound literals, and it has integer constants.
But C does not have integer literals.
>
Technically correct (but IMHO not really worth worrying about).
>
Anyone who flogs others posters for incorrectly using terminology
defined in the ISO C standard should set a good example by using
the ISO-C-defined terms correctly himself.
In fact I do. In my own writing, I use the term "integer constant",
not "integer literal", when discussing C. (It's likely I haven't
been 100% consistent.)
My point is that, while "integer literal" is inconsistent with the
terminology used in the C standard, it is not ambiguous or confusing.
C does not define the term "literal" (it defines the phrases "string
literal" and "compound literal"). The word "literal" by itself
is a very common term used when discussing programs in general.
When I looked into it last time this came up, I found that most of
the programming languages I looked into refer to 42 as a literal,
not as a constant.
I'll also note that the word "constant" is overloaded in C.
For example, as of C17, the description of "sizeof" says: "If the
type of the operand is a variable length array type, the operand
is evaluated; otherwise, the operand is not evaluated and the
result is an integer constant." Though the meaning is clear,
it's an incorrect usage. (C23 changes this to "... and the result
is an integer constant expression", which is better, but it's the
expression, not its result, that is an integer constant expression.)
Replacing the term "constant" by "literal" would, in my opinion,
improve the clarity of the standard. I see no drawbacks to such
a change (other than the overhead of *any* change to the standard).
There is a proposal for C2y, authored by Jens Gustedt, to change the
term "constant" to "literal" for character, integer, and floating
constants. (I think it's a good idea.)
>
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3239.htm>
>
The more C is changed to resemble C++ the worse it becomes. It
isn't surprising that you like it.
I presume that was intended as a personal insult. I urge you to do
better.
I acknowledge your opinion. I do not share it.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */