| Deutsch English Français Italiano |
|
<87plmfu2ub.fsf@nosuchdomain.example.com> 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: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: question about linker
Date: Thu, 28 Nov 2024 01:25:48 -0800
Organization: None to speak of
Lines: 46
Message-ID: <87plmfu2ub.fsf@nosuchdomain.example.com>
References: <vi54e9$3ie0o$1@dont-email.me> <vi6sb1$148h7$1@paganini.bofh.team>
<vi6uaj$3ve13$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Thu, 28 Nov 2024 10:25:49 +0100 (CET)
Injection-Info: dont-email.me; posting-host="5d82f7250b92e1d8e1e5ba7e656a3e2b";
logging-data="518284"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+T/WXGdufwGmOQ+uS1IloY"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:4v5R1L/5uz4+pXmlNsR5tc3PGpE=
sha1:DkVb6SLZWRGX+PKyJCg2IvCcTjA=
Bytes: 2734
Thiago Adams <thiago.adams@gmail.com> writes:
> On 27/11/2024 07:29, Waldek Hebisch wrote:
[...]
>> 1) campilers for embedded targets care very much about const. const
>> qualified arrays go into read-only data section which is typically
>> located in flash. Other arrays go to RAM. Embedded targets
>> frequently have very small RAM and larger flash, so after
>> dropping const program may no longer fit in available RAM.
>
> I think your comment applies for const in declarations like
>
> const int i = 1;
>
> I used to find const confusing, as it sometimes meant 'read-only' and
> other times 'immutable.'
I'm not sure what you mean. My understanding is that const means
read-only, and nothing else.
> Now, it seems less confusing to me. When const is used with variables
> that can be initialized (init-declarator), it acts as 'immutable',
> meaning the storage is constant.
What exactly do you mean by "the storage is constant"? Are you talking
about memory that is marked as read-only by the OS?
Given something like:
const int r = rand();
at block scope, the object will almost certainly be stored in ordinary
read/write memory. The compiler will flag code that attempts to modify
it (unless you play tricks with pointer casts, which can introduce
undefined behavior). But if I do something like `*(int*)&r = 42;`,
it's likely to "work".
Defining an object as const can *enable* a compiler to store it in
read-only memory (enforced by the OS, or maybe even physical RAM on some
systems), but that's an implementation choice, not part of the semantics
of const.
[...]
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */