Re: relearning C: why does an in-place change to a char* segfault?

Liste des GroupesRevenir à cl c  
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.c
Date : 28. Sep 2024, 23:17:10
Autres entêtes
Organisation : None to speak of
Message-ID : <87wmivqv89.fsf@nosuchdomain.example.com>
References : 1 2
User-Agent : Gnus/5.13 (Gnus v5.13)
Phillip Frabott <nntp@fulltermprivacy.com> writes:
In reply to "Keith Thompson" who wrote the following:
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").
>
In the context of C I agree. Although I would point out that for some langauges
const and readonly are two completely different things. (just a brevity remark,
but I'll get back on topic now)
>
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.
>
Maybe the expression can be determined/evaluated at compile time but not the
result. When I think of literals the resulting value has to be determined at
compile time. So const int r = 15; would be to me a literal result. The compiler
can bake that in without needing further runtime execution to get such result.
But a const can be either a literal or non-literal in my view. Anything that
cannot give a predetermined value at compile time is a const. So to me:
>
const int r = rand();
>
is not a literal only because the output of rand() is unknown until
runtime.

Of course that's not a literal, nor is it constant.  The object r is
*const* (its value cannot be changed after its initialization), not
*constant*.

From a human-readable code perspective I get it. And fine, there can be a
similarity between const and literal on the surface. But the moment you need to
know exactly what the compiler is doing, those two things have to be separate.

Certainly "const" and "literal" are separate.  They mean almost
completely different things.

I can't help wondering if you missed the point.

A literal, as the term is commonly used, is a single token that
represents a constant (compile-time) value of some type.  Examples are
42 and "foo".  (C compound literals are more complicated.)

C uses the term "constant" (as a noun) for tokens of numeric types, like
42 and 1.5, that represent compile-time values.  C2Y will likely refer
to these as "literals".  See
    https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3239.htm
which is the proposal to use the word "literal", and
    https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3301.pdf
particularly section 6.4.5, which is a C2Y draft that incorporates the
proposal (when open-std.org is up and running again).

The word "constant" is also used as an adjective in the phrase "constant
expression".  A constant expression,  like (2+2), is one that's required
to be evaluated at compile time in certain contexts, so it can't refer
to the value of a variable.

The keyword "const" is almost unrelated to either "const" or "literal".
It means that an object cannot legally be modified after it's been
initialized.

The planned change for C2Y is to use the word "literal" rather than
"constant".  There's no change to the phrase "constant expression".

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
1 Aug 24 * relearning C: why does an in-place change to a char* segfault?105Mark Summerfield
1 Aug 24 +* Re: relearning C: why does an in-place change to a char* segfault?2Mark Summerfield
1 Aug 24 i`- Re: relearning C: why does an in-place change to a char* segfault?1Ben Bacarisse
1 Aug 24 +* Re: relearning C: why does an in-place change to a char* segfault?40Richard Harnden
1 Aug 24 i+- Re: relearning C: why does an in-place change to a char* segfault?1Mark Summerfield
1 Aug 24 i`* Re: relearning C: why does an in-place change to a char* segfault?38Bart
1 Aug 24 i `* Re: relearning C: why does an in-place change to a char* segfault?37Keith Thompson
1 Aug 24 i  +* Re: relearning C: why does an in-place change to a char* segfault?27Bart
1 Aug 24 i  i+- Re: relearning C: why does an in-place change to a char* segfault?1Keith Thompson
2 Aug 24 i  i+- Re: relearning C: why does an in-place change to a char* segfault?1James Kuyper
2 Aug 24 i  i+* Re: relearning C: why does an in-place change to a char* segfault?23Kaz Kylheku
2 Aug 24 i  ii`* Re: relearning C: why does an in-place change to a char* segfault?22Bart
2 Aug 24 i  ii +- Re: relearning C: why does an in-place change to a char* segfault?1Richard Damon
2 Aug 24 i  ii `* Re: relearning C: why does an in-place change to a char* segfault?20James Kuyper
2 Aug 24 i  ii  +- Re: relearning C: why does an in-place change to a char* segfault?1Bart
3 Aug 24 i  ii  +* Re: relearning C: why does an in-place change to a char* segfault?5Lawrence D'Oliveiro
3 Aug 24 i  ii  i`* Re: relearning C: why does an in-place change to a char* segfault?4Richard Damon
3 Aug 24 i  ii  i +- Re: relearning C: why does an in-place change to a char* segfault?1Joe Pfeiffer
4 Aug 24 i  ii  i +- Re: relearning C: why does an in-place change to a char* segfault?1Lawrence D'Oliveiro
12 Aug 24 i  ii  i `- Re: relearning C: why does an in-place change to a char* segfault?1Tim Rentsch
14 Aug 24 i  ii  `* Re: relearning C: why does an in-place change to a char* segfault?13Tim Rentsch
14 Aug 24 i  ii   +* Re: relearning C: why does an in-place change to a char* segfault?10Keith Thompson
16 Aug 24 i  ii   i`* Re: relearning C: why does an in-place change to a char* segfault?9Tim Rentsch
16 Aug 24 i  ii   i `* Re: relearning C: why does an in-place change to a char* segfault?8Keith Thompson
28 Sep 24 i  ii   i  `* Re: relearning C: why does an in-place change to a char* segfault?7Tim Rentsch
28 Sep 24 i  ii   i   `* Re: relearning C: why does an in-place change to a char* segfault?6Keith Thompson
28 Sep 24 i  ii   i    `* Re: relearning C: why does an in-place change to a char* segfault?5Janis Papanagnou
28 Sep 24 i  ii   i     `* Re: relearning C: why does an in-place change to a char* segfault?4Phillip Frabott
28 Sep 24 i  ii   i      `* Re: relearning C: why does an in-place change to a char* segfault?3Keith Thompson
29 Sep 24 i  ii   i       `* Re: relearning C: why does an in-place change to a char* segfault?2Phillip Frabott
29 Sep 24 i  ii   i        `- Re: relearning C: why does an in-place change to a char* segfault?1Keith Thompson
14 Aug 24 i  ii   `* Re: relearning C: why does an in-place change to a char* segfault?2James Kuyper
16 Aug 24 i  ii    `- Re: relearning C: why does an in-place change to a char* segfault?1Tim Rentsch
4 Aug 24 i  i`- Re: relearning C: why does an in-place change to a char* segfault?1Bonita Montero
12 Aug 24 i  `* Re: relearning C: why does an in-place change to a char* segfault?9Tim Rentsch
13 Aug 24 i   `* Re: relearning C: why does an in-place change to a char* segfault?8Vir Campestris
13 Aug 24 i    +* Re: relearning C: why does an in-place change to a char* segfault?3Keith Thompson
14 Aug 24 i    i+- Re: relearning C: why does an in-place change to a char* segfault?1Tim Rentsch
14 Aug 24 i    i`- Re: relearning C: why does an in-place change to a char* segfault?1David Brown
14 Aug 24 i    `* Re: relearning C: why does an in-place change to a char* segfault?4Tim Rentsch
14 Aug 24 i     `* Re: relearning C: why does an in-place change to a char* segfault?3Keith Thompson
14 Aug 24 i      `* Re: relearning C: why does an in-place change to a char* segfault?2Kaz Kylheku
14 Aug 24 i       `- Re: relearning C: why does an in-place change to a char* segfault?1Keith Thompson
1 Aug 24 +* No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?38Michael S
1 Aug 24 i`* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?37David Brown
2 Aug 24 i `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?36candycanearter07
2 Aug 24 i  +* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?34Keith Thompson
2 Aug 24 i  i+* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?28Richard Harnden
2 Aug 24 i  ii+- Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?1James Kuyper
2 Aug 24 i  ii+* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?24Keith Thompson
2 Aug 24 i  iii+* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?5Richard Damon
2 Aug 24 i  iiii+* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?3James Kuyper
2 Aug 24 i  iiiii`* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?2Richard Damon
12 Aug 24 i  iiiii `- Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?1Tim Rentsch
12 Aug 24 i  iiii`- Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?1Tim Rentsch
2 Aug 24 i  iii+* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?15Chris M. Thomasson
3 Aug 24 i  iiii`* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?14Ben Bacarisse
3 Aug 24 i  iiii `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?13Chris M. Thomasson
5 Aug 24 i  iiii  `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?12Ben Bacarisse
5 Aug 24 i  iiii   `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?11Chris M. Thomasson
5 Aug 24 i  iiii    +- Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?1Chris M. Thomasson
5 Aug 24 i  iiii    `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?9Ben Bacarisse
5 Aug 24 i  iiii     `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?8Chris M. Thomasson
5 Aug 24 i  iiii      `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?7Ben Bacarisse
6 Aug 24 i  iiii       +* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?5Chris M. Thomasson
6 Aug 24 i  iiii       i`* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?4Ben Bacarisse
6 Aug 24 i  iiii       i `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?3Chris M. Thomasson
7 Aug 24 i  iiii       i  `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?2Ben Bacarisse
13 Aug 24 i  iiii       i   `- Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?1Chris M. Thomasson
6 Aug 24 i  iiii       `- Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?1Chris M. Thomasson
12 Aug 24 i  iii`* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?3Tim Rentsch
12 Aug 24 i  iii `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?2Keith Thompson
3 Sep 24 i  iii  `- Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?1Tim Rentsch
25 Aug 24 i  ii`* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?2dave thompson 2
25 Aug 24 i  ii `- Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?1Keith Thompson
12 Aug 24 i  i`* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?5Tim Rentsch
12 Aug 24 i  i `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?4Keith Thompson
13 Aug 24 i  i  `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?3Tim Rentsch
13 Aug 24 i  i   `* Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?2David Brown
13 Aug 24 i  i    `- Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?1Keith Thompson
3 Aug 24 i  `- Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?1David Brown
1 Aug 24 +- Re: relearning C: why does an in-place change to a char* segfault?1James Kuyper
1 Aug 24 `* Re: relearning C: why does an in-place change to a char* segfault?23Kaz Kylheku
1 Aug 24  +* Re: relearning C: why does an in-place change to a char* segfault?20Bart
1 Aug 24  i+- Re: relearning C: why does an in-place change to a char* segfault?1Keith Thompson
1 Aug 24  i+- Re: relearning C: why does an in-place change to a char* segfault?1Ben Bacarisse
2 Aug 24  i+* Re: relearning C: why does an in-place change to a char* segfault?3Kaz Kylheku
2 Aug 24  ii+- Re: relearning C: why does an in-place change to a char* segfault?1Bart
12 Aug 24  ii`- Re: relearning C: why does an in-place change to a char* segfault?1Tim Rentsch
3 Aug 24  i`* Re: relearning C: why does an in-place change to a char* segfault?14David Brown
4 Aug 24  i +* Re: relearning C: why does an in-place change to a char* segfault?12Keith Thompson
4 Aug 24  i i+* Re: relearning C: why does an in-place change to a char* segfault?10Lawrence D'Oliveiro
4 Aug 24  i ii`* Re: relearning C: why does an in-place change to a char* segfault?9Keith Thompson
4 Aug 24  i ii +* Re: relearning C: why does an in-place change to a char* segfault?2Richard Damon
12 Aug 24  i ii i`- Re: relearning C: why does an in-place change to a char* segfault?1Tim Rentsch
5 Aug 24  i ii `* Re: relearning C: why does an in-place change to a char* segfault?6Lawrence D'Oliveiro
5 Aug 24  i ii  `* Re: relearning C: why does an in-place change to a char* segfault?5Keith Thompson
5 Aug 24  i ii   `* Re: relearning C: why does an in-place change to a char* segfault?4Lawrence D'Oliveiro
6 Aug 24  i ii    `* Re: relearning C: why does an in-place change to a char* segfault?3Keith Thompson
6 Aug 24  i ii     `* Re: relearning C: why does an in-place change to a char* segfault?2Bart
6 Aug 24  i ii      `- Re: relearning C: why does an in-place change to a char* segfault?1David Brown
4 Aug 24  i i`- Re: relearning C: why does an in-place change to a char* segfault?1David Brown
4 Aug 24  i `- Re: relearning C: why does an in-place change to a char* segfault?1Keith Thompson
1 Aug 24  +- Re: relearning C: why does an in-place change to a char* segfault?1Keith Thompson
14 Aug 24  `- Re: relearning C: why does an in-place change to a char* segfault?1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal