| Deutsch English Français Italiano |
|
<slrnvkjbhl.78r.ike@iceland.freeshell.org> 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: Ike Naar <ike@sdf.org>
Newsgroups: comp.lang.c
Subject: Re: question about linker
Date: Fri, 29 Nov 2024 12:06:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <slrnvkjbhl.78r.ike@iceland.freeshell.org>
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>
<vi9kng$gn4c$1@dont-email.me> <87frnbt9jn.fsf@nosuchdomain.example.com>
<viaqh0$nm7q$1@dont-email.me> <877c8nt255.fsf@nosuchdomain.example.com>
<viasv4$nm7q$2@dont-email.me> <vibr1l$vvjf$1@dont-email.me>
<vic73f$1205f$1@dont-email.me>
Injection-Date: Fri, 29 Nov 2024 13:06:14 +0100 (CET)
Injection-Info: dont-email.me; posting-host="bffdfbaa8bf3f56be8b48300bb2e6f2f";
logging-data="1142398"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4Zm243YoNJp8ZOdzYjDpp"
User-Agent: slrn/1.0.3 (Patched for libcanlock3) (NetBSD)
Cancel-Lock: sha1:V6ujG9swi2MC/bHmu0t/5J9AJWs=
Bytes: 2516
On 2024-11-29, Bart <bc@freeuk.com> wrote:
> These are similar examples:
>
> int * const z1;
> int const * z2;
>
> z1=0; // invalid
> z2=0; // valid
>
> [snip]
>
> Both 'const' in my new examples are the the right-most one! Yet one
> makes the immediate storage const and one doesn't. I guess then that
> it's the right-most possible 'const' if it were to be used. In my
> example, that would follow the '*'.
The order in which '*' and 'const' appear matters.
With
int * const z1;
the const applies to z1 because it appears immediately before 'z1'.
z1 is a const pointer to int.
(hint: read the declaration out loud from right to left).
*z1 = 0; /* valid */
z1 = 0; /* invalid, z1 is readonly */
With
int const * z2;
the const applies to *z2 because it appears immediately before '* z2'.
*z2 is a const int, z2 is a pointer to const int.
(again, read the declaration out loud from right to left).
*z2 = 0; /* invalid, *z2 is readonly */
z2 = 0; /* valid */
With
int const * const z3;
the leftmost const applies to *z3 and the rightmost const applies to z3.
z3 is a const pointer to const int.
*z3 = 0; /* invalid, *z3 is readonly */
z3 = 0; /* invalid, z3 is readonly */