Deutsch   English   Français   Italiano  
<vi9kng$gn4c$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: question about linker
Date: Thu, 28 Nov 2024 11:38:25 +0000
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <vi9kng$gn4c$1@dont-email.me>
References: <vi54e9$3ie0o$1@dont-email.me> <vi6sb1$148h7$1@paganini.bofh.team>
 <vi6uaj$3ve13$2@dont-email.me> <87plmfu2ub.fsf@nosuchdomain.example.com>
 <vi9jk4$gse4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Nov 2024 12:38:25 +0100 (CET)
Injection-Info: dont-email.me; posting-host="033a1fb1a70fe4f5596322438ef79f57";
	logging-data="547980"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+31v/8LCSFAatOQtFLmf2S"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:LCFTrFldISkGgGFroFv3L+nXum8=
Content-Language: en-GB
In-Reply-To: <vi9jk4$gse4$1@dont-email.me>
Bytes: 2291

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];