From: Bruce Guenter <bruceg@em.ca>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] warnkill trivia 2/2
Date: Sun, 1 Sep 2002 15:57:49 -0600 [thread overview]
Message-ID: <20020901155749.A8323@em.ca> (raw)
In-Reply-To: <20020901123903.GB7325@louise.pinerecords.com>; from szepe@pinerecords.com on Sun, Sep 01, 2002 at 02:39:03PM +0200
[-- Attachment #1: Type: text/plain, Size: 1319 bytes --]
On Sun, Sep 01, 2002 at 02:39:03PM +0200, Tomas Szepe wrote:
> I've been playing a bit with how gcc handles the const qualifiers
> and made an interesting discovery:
>
> Trying to compile
>
> typedef int *p_int;
> void a(const p_int t) { *t = 0; }
> void b(const p_int t) { t = (int *) 0; }
> void c(const int *t) { *t = 0; }
> void d(const int *t) { t = (int *) 0; }
> void e(int const *t) { *t = 0; }
> void f(int const *t) { t = (int *) 0; }
>
> will give 'assignment of read-only location' warnings for
> b(), c() and e(), i.e. it's impossible to have a constant
> pointer to a non-constant value w/o using a qualified
> typedef.
If you want a constant *pointer*, use:
void f(int* const t)
(read "f is a function, taking parameter constant pointer to
int, returning void)
> W/o a typedef, gcc seems unable to tell the difference
> between 'const int *' and 'int const *' altogether.
That's because there is no difference ("pointer to integer constant" vs
"pointer to constant integer").
See http://untroubled.org/articles/cdecls.txt for one of the best
references I've ever seen to understanding C type declarations.
--
Bruce Guenter <bruceg@em.ca> http://em.ca/~bruceg/ http://untroubled.org/
OpenPGP key: 699980E8 / D0B7 C8DD 365D A395 29DA 2E2A E96F B2DC 6999 80E8
[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]
next prev parent reply other threads:[~2002-09-01 21:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-09-01 10:56 [PATCH] warnkill trivia 2/2 Tomas Szepe
2002-09-01 10:57 ` David S. Miller
2002-09-01 11:28 ` Tomas Szepe
2002-09-01 11:25 ` David S. Miller
2002-09-01 11:37 ` Tomas Szepe
2002-09-01 11:35 ` David S. Miller
2002-09-01 12:10 ` Tomas Szepe
2002-09-01 12:16 ` David S. Miller
2002-09-01 12:39 ` Tomas Szepe
2002-09-01 21:57 ` Bruce Guenter [this message]
2002-09-02 22:24 ` Jan Hudec
2002-09-01 15:27 ` [PATCH] warnkill trivia 2/2 (correction) Tomas Szepe
-- strict thread matches above, loose matches on Subject: below --
2002-09-01 14:52 [PATCH] warnkill trivia 2/2 Mikael Pettersson
2002-09-01 14:56 ` Tomas Szepe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020901155749.A8323@em.ca \
--to=bruceg@em.ca \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.