Sujet : Re: question about linker
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 28. Nov 2024, 12:38:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vi9kng$gn4c$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
On 28/11/2024 11:19, Thiago Adams wrote:
On 28/11/2024 06:25, Keith Thompson wrote:
What exactly do you mean by "the storage is constant"? Are you talking
about memory that is marked as read-only by the OS?
Here comes another point (that I realized after I wrote that) and that makes const more confusing.
I think 'const' is confusing for similar reasons that VLAs can be both confusing and awkward to implement.
That's because both really apply to /types/, not directly to variables.
So both const and a VLA can specified deep inside a type-spec, where there may be no storage allocated, inside a cast for example, but here's a simpler one:
int n;
const int (*A)[n];
This declares a pointer to a VLA, so no storage is allocated for the VLA. (I'm not even sure how you'd allocate it in the program, given that VLAs normally go on the stack.)
And the 'const' applies to the array elements, which here don't exist. To make the pointer itself const, then 'const' needs to be at the top-level, which bizarrely needs to go not only in the middle, but /after/ the pointer which is to be const:
const int (*const A)[n];