So You Think You Can Const?

Liste des GroupesRevenir à cl c 
Sujet : So You Think You Can Const?
De : julio (at) *nospam* diegidio.name (Julio Di Egidio)
Groupes : comp.lang.c
Date : 07. Jan 2025, 20:32:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vljvh3$27msl$1@dont-email.me>
User-Agent : Mozilla Thunderbird
Hi everybody,
I am back to programming in C after many years:
indeed I have forgotten so many things, including
how much I love this language. :)
In particular, I am using C90, and compiling with
`gcc ... -ansi -pedantic -Wall -Wextra` (as I have
the requirement to ideally support any device).
To the question, I was reading this, but I am not
sure what the quoted passage means:
Matt Stancliff, "So You Think You Can Const?",
<https://matt.sh/sytycc>
<< Your compiler, at its discretion, may also choose
    to place any const declarations in read-only storage,
    so if you attempt to hack around the const blocks,
    you could get undefined behavior. >>
I do not understand if just declaring that a pointer
is to constant data may incur in that problem even
if the pointed data was in fact allocated with malloc.
I would say of course not, but I am not sure.
E.g. consider this little internal helper of mine
(which implements an interface that is public to
do an internal thing...), where I am casting to
pointer to non-constant data in order to free the
pointed data (i.e. without warning):
```c
static int MyStruct_free_(MyStruct_t const *pT) {
     assert(pT);
     free((MyStruct_t *)pT);
     return 0;
}
```
Assuming, as said, that the data was originally
allocated with malloc, is that code safe or
something can go wrong even in that case?
Thank in advance for any help/insight,
Julio

Date Sujet#  Auteur
7 Jan 25 * So You Think You Can Const?174Julio Di Egidio
7 Jan 25 +* Re: So You Think You Can Const?80Kaz Kylheku
8 Jan 25 i`* Re: So You Think You Can Const?79Julio Di Egidio
8 Jan 25 i +- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i `* Re: So You Think You Can Const?77Ben Bacarisse
8 Jan 25 i  +- Re: So You Think You Can Const?1David Brown
8 Jan 25 i  +* Re: So You Think You Can Const?72Julio Di Egidio
8 Jan 25 i  i+* Re: So You Think You Can Const?64Julio Di Egidio
8 Jan 25 i  ii+- Re: So You Think You Can Const?1Chris M. Thomasson
9 Jan 25 i  ii`* Re: So You Think You Can Const?62Ben Bacarisse
9 Jan 25 i  ii +* Re: So You Think You Can Const?4Kaz Kylheku
9 Jan 25 i  ii i`* Re: So You Think You Can Const?3David Brown
9 Jan 25 i  ii i +- Re: So You Think You Can Const?1Chris M. Thomasson
15 Jan 25 i  ii i `- Re: So You Think You Can Const?1Julio Di Egidio
9 Jan 25 i  ii +* Re: So You Think You Can Const?54Julio Di Egidio
10 Jan 25 i  ii i`* Re: So You Think You Can Const?53Ben Bacarisse
10 Jan 25 i  ii i +* Re: So You Think You Can Const?46Julio Di Egidio
10 Jan 25 i  ii i i+* Re: So You Think You Can Const?44Julio Di Egidio
10 Jan 25 i  ii i ii`* Re: So You Think You Can Const?43Tim Rentsch
10 Jan 25 i  ii i ii +* Re: So You Think You Can Const?38Julio Di Egidio
10 Jan 25 i  ii i ii i+* Re: So You Think You Can Const?36Julio Di Egidio
10 Jan 25 i  ii i ii ii+- Re: So You Think You Can Const?1Julio Di Egidio
13 Jan 25 i  ii i ii ii`* Re: So You Think You Can Const?34James Kuyper
13 Jan 25 i  ii i ii ii +* Re: So You Think You Can Const?32David Brown
13 Jan 25 i  ii i ii ii i+* Re: So You Think You Can Const?29Julio Di Egidio
13 Jan 25 i  ii i ii ii ii`* Re: So You Think You Can Const?28David Brown
13 Jan 25 i  ii i ii ii ii +* Re: So You Think You Can Const?26Julio Di Egidio
13 Jan 25 i  ii i ii ii ii i`* Re: So You Think You Can Const?25David Brown
14 Jan 25 i  ii i ii ii ii i +* Re: So You Think You Can Const?22Julio Di Egidio
14 Jan 25 i  ii i ii ii ii i i+* Re: So You Think You Can Const?16bart
14 Jan 25 i  ii i ii ii ii i ii`* Re: So You Think You Can Const?15David Brown
14 Jan 25 i  ii i ii ii ii i ii +* Re: So You Think You Can Const?7James Kuyper
14 Jan 25 i  ii i ii ii ii i ii i+- Re: So You Think You Can Const?1Dan Cross
14 Jan 25 i  ii i ii ii ii i ii i`* Re: So You Think You Can Const?5David Brown
14 Jan 25 i  ii i ii ii ii i ii i `* Re: So You Think You Can Const?4James Kuyper
15 Jan 25 i  ii i ii ii ii i ii i  `* Re: So You Think You Can Const?3James Kuyper
15 Jan 25 i  ii i ii ii ii i ii i   `* Re: So You Think You Can Const?2David Brown
15 Jan 25 i  ii i ii ii ii i ii i    `- Re: So You Think You Can Const?1Julio Di Egidio
14 Jan 25 i  ii i ii ii ii i ii +* Re: So You Think You Can Const?2Chris M. Thomasson
14 Jan 25 i  ii i ii ii ii i ii i`- Re: So You Think You Can Const?1Chris M. Thomasson
15 Jan 25 i  ii i ii ii ii i ii `* Re: So You Think You Can Const?5Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i ii  +- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i ii  `* Re: So You Think You Can Const?3Kaz Kylheku
15 Jan 25 i  ii i ii ii ii i ii   `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i ii    `- Re: So You Think You Can Const?1Julio Di Egidio
14 Jan 25 i  ii i ii ii ii i i+- Re: So You Think You Can Const?1James Kuyper
14 Jan 25 i  ii i ii ii ii i i`* Re: So You Think You Can Const?4Keith Thompson
15 Jan 25 i  ii i ii ii ii i i `* Re: So You Think You Can Const?3Kenny McCormack
15 Jan 25 i  ii i ii ii ii i i  `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i i   `- Re: So You Think You Can Const?1Kaz Kylheku
15 Jan 25 i  ii i ii ii ii i `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i  `- Re: So You Think You Can Const?1Kaz Kylheku
15 Jan 25 i  ii i ii ii ii `- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii i ii ii i`* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii i `- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii i ii ii `- Re: So You Think You Can Const?1Julio Di Egidio
13 Jan 25 i  ii i ii i`- Re: So You Think You Can Const?1Tim Rentsch
15 Jan 25 i  ii i ii `* Re: So You Think You Can Const?4Julio Di Egidio
18 Jan 25 i  ii i ii  `* Re: So You Think You Can Const?3Tim Rentsch
19 Jan 25 i  ii i ii   `* Re: So You Think You Can Const?2Julio Di Egidio
20 Jan 25 i  ii i ii    `- Re: So You Think You Can Const?1Chris M. Thomasson
10 Jan 25 i  ii i i`- Re: So You Think You Can Const?1Ben Bacarisse
12 Jan 25 i  ii i +* Re: So You Think You Can Const?5Waldek Hebisch
12 Jan 25 i  ii i i+* Re: So You Think You Can Const?3Julio Di Egidio
13 Jan 25 i  ii i ii`* Re: So You Think You Can Const?2David Brown
13 Jan 25 i  ii i ii `- Re: So You Think You Can Const?1James Kuyper
13 Jan 25 i  ii i i`- Re: So You Think You Can Const?1David Brown
15 Jan 25 i  ii i `- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii +- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii  `- Re: So You Think You Can Const?1Chris M. Thomasson
8 Jan 25 i  i+* Re: So You Think You Can Const?2James Kuyper
8 Jan 25 i  ii`- Re: So You Think You Can Const?1James Kuyper
8 Jan 25 i  i+* Re: So You Think You Can Const?2Tim Rentsch
9 Jan 25 i  ii`- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i  i+- Re: So You Think You Can Const?1Chris M. Thomasson
9 Jan 25 i  i`* Re: So You Think You Can Const?2Ben Bacarisse
9 Jan 25 i  i `- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i  +* Re: So You Think You Can Const?2Tim Rentsch
9 Jan 25 i  i`- Re: So You Think You Can Const?1Ben Bacarisse
15 Jan 25 i  `- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 +* Re: So You Think You Can Const?35David Brown
8 Jan 25 i+* Re: So You Think You Can Const?4Ben Bacarisse
8 Jan 25 ii`* Re: So You Think You Can Const?3David Brown
15 Jan 25 ii `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 ii  `- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i+* What is wrong with malloc? (Was: So You Think You Can Const?)28Julio Di Egidio
8 Jan 25 ii+* Re: What is wrong with malloc? (Was: So You Think You Can Const?)25David Brown
8 Jan 25 iii+* Re: What is wrong with malloc? (Was: So You Think You Can Const?)2Julio Di Egidio
8 Jan 25 iiii`- Re: What is wrong with malloc? (Was: So You Think You Can Const?)1David Brown
8 Jan 25 iii+* Re: What is wrong with malloc? (Was: So You Think You Can Const?)13Phillip
8 Jan 25 iiii+- Re: What is wrong with malloc? (Was: So You Think You Can Const?)1Tim Rentsch
8 Jan 25 iiii+* Re: What is wrong with malloc?10Keith Thompson
8 Jan 25 iiiii`* Re: What is wrong with malloc?9Phillip
8 Jan 25 iiiii `* Re: What is wrong with malloc?8Keith Thompson
9 Jan 25 iiiii  `* Re: What is wrong with malloc?7Phillip
9 Jan 25 iiiii   +* Re: What is wrong with malloc?4Keith Thompson
9 Jan 25 iiiii   i+- Re: What is wrong with malloc?1Phillip
9 Jan 25 iiiii   i`* Re: What is wrong with malloc?2Michael S
9 Jan 25 iiiii   i `- Re: What is wrong with malloc?1Phillip
9 Jan 25 iiiii   `* Re: What is wrong with malloc?2David Brown
9 Jan 25 iiii`- Re: What is wrong with malloc? (Was: So You Think You Can Const?)1David Brown
8 Jan 25 iii+* Re: What is wrong with malloc?3Keith Thompson
9 Jan 25 iii`* Re: What is wrong with malloc? (Was: So You Think You Can Const?)6Julio Di Egidio
8 Jan 25 ii`* Re: What is wrong with malloc? (Was: So You Think You Can Const?)2James Kuyper
8 Jan 25 i+- Re: So You Think You Can Const?1Kaz Kylheku
8 Jan 25 i`- Re: So You Think You Can Const?1Keith Thompson
8 Jan 25 +* Re: So You Think You Can Const?51Andrey Tarasevich
8 Jan 25 +- Re: So You Think You Can Const?1Tim Rentsch
13 Jan 25 +- Re: So You Think You Can Const?1Chris M. Thomasson
15 Jan 25 +* Re: So You Think You Can Const?4Lawrence D'Oliveiro
26 Jan 25 `- Re: So You Think You Can Const?1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal