From: Jamie Lokier <jamie@shareable.org>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] const / static (against current CVS)
Date: Wed, 24 Aug 2005 21:35:40 +0100 [thread overview]
Message-ID: <20050824203540.GC31875@mail.shareable.org> (raw)
In-Reply-To: <200508241441.45656.paul@codesourcery.com>
Paul Brook wrote:
> Contrary to popular belief the "const" qualifier on pointers has
> absolutely no effect on optimization. It's simply a debugging aid so
> the compiler will generate an error if you accidentally assign to
> it.
That's only true when the "const" applies to pointer targets, as in:
const char * ptr = "foo";
It does not apply when the "const" applies to the pointer itself.
This puts the pointer "ptr" into RO storage:
const char * const ptr = "foo";
Hence the large number of times that pattern occurs in the patch.
> It's perfectly legal to cast a (const char *) to a (char *) then
> dereference and write to it, provided the object the object it
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> points to is modifiable.
^^^^^^^^^^^^^^^^^^^^^^^
Precisely. Global and static variables that are declared "const" are
not "modifiable", and are put in RO storage, so they cannot be written
to. Taking their address creates a "const" pointer which must not be
derefenced and written to.
-- Jamie
prev parent reply other threads:[~2005-08-24 20:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-23 17:40 [Qemu-devel] [PATCH] const / static (against current CVS) Andreas Mohr
2005-08-24 3:24 ` Mulyadi Santosa
2005-08-24 12:54 ` Doctor Bill
2005-08-24 13:41 ` Paul Brook
2005-08-24 14:38 ` Andreas Mohr
2005-08-24 14:49 ` Paul Brook
2005-08-24 16:49 ` Doctor Bill
2005-08-24 20:35 ` Jamie Lokier [this message]
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=20050824203540.GC31875@mail.shareable.org \
--to=jamie@shareable.org \
--cc=qemu-devel@nongnu.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.