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 : nntp (at) *nospam* fulltermprivacy.com (Phillip Frabott)
Groupes : comp.lang.c
Date : 28. Sep 2024, 23:05:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vd9uja$1drtq$1@dont-email.me>
References : 1
User-Agent : NewsLeecher v7.0 Final (http://www.newsleecher.com)
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.
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.

Perhaps there is a better way to do it. Or maybe there can be a literal type
that is basically equal to const type for the purpose of coding or even perhaps
a [--treat-const-as-literal] compiler parameter for code where a literal value
and a const value should be treated the same. But I still think these two should
be treated differently.

I should note I don't have the original posting for this thread (I guess my
provider doesn't have it) so I don't have the original URI that started this
thread. If someone can share it in a reply I'd really appreciate it so I can be
sure I'm on the same page with what is being discussed.
Phillip Frabott
{Adam: Is a void really a void if it returns? - Jack: No, it's just nullspace at
that point.}


--
----------------------------------------- --- -- -
Posted with NewsLeecher v7.0 Final
Free Newsreader @ http://www.newsleecher.com/
------------------------------- ----- ---- -- -


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