Liste des Groupes | Revenir à cl c |
On 2025-01-07, Julio Di Egidio <julio@diegidio.name> wrote:<snipped>
What do you/we mean by "object" in this context? (Sorry, I do have forgotten, the glossary to begin with.)In particular, I am using C90, and compiling withAn object defined with a type that is const-qualified
`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. >>
could be put into write-protected storage.
Objects coming from malloc are not defined by a declaration.I vaguely remember the use of "declaration" vs "definition" I used to find confusing at the time, but some three decades have passed, maybe now I can do better...
ISO C defines the term /effective type/ (// indicates italics)Thank you so much overall, for the explanations and the final assessment: I couldn't hope for a better answer.
for the purposes of stating some rules regarding expressions accessing
objects. "The /effective type/ of an object that is not a byte array,
for an access to its stored value, is the declared type of the object"
says the N3301 draft of C23 in section 6.5.1 Expressions/General.
A footnote to this sentence clarifies that "allocated objects have no
declared type", almost certainly meaning dynamically allocated by
the malloc family.
How you got the "const MyStruct_t *" pointer is that you firstI was actually going out of my way trying to const-ify everything while trying not to cast anywhere: I totally misremembered what these things actually mean in C, and adding const everywhere possible is one of the habits I have meanwhile acquired from other languages. But it's coming back... I *will* do as you say. :)
treated the object as "MyStruct_t *", and filled in its members.
Then you cast the pointer to "const MyStruct_t *".
Les messages affichés proviennent d'usenet.