From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1E82A1-0005UT-Cf for qemu-devel@nongnu.org; Wed, 24 Aug 2005 16:47:52 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1E829j-0005Py-7o for qemu-devel@nongnu.org; Wed, 24 Aug 2005 16:47:34 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E829j-0005Ku-4F for qemu-devel@nongnu.org; Wed, 24 Aug 2005 16:47:31 -0400 Received: from [81.29.64.88] (helo=mail.shareable.org) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1E81zP-0001G3-ME for qemu-devel@nongnu.org; Wed, 24 Aug 2005 16:36:51 -0400 Received: from mail.shareable.org (localhost [127.0.0.1]) by mail.shareable.org (8.12.8/8.12.8) with ESMTP id j7OKZe6K032085 for ; Wed, 24 Aug 2005 21:35:40 +0100 Received: (from jamie@localhost) by mail.shareable.org (8.12.8/8.12.8/Submit) id j7OKZe6F032083 for qemu-devel@nongnu.org; Wed, 24 Aug 2005 21:35:40 +0100 Date: Wed, 24 Aug 2005 21:35:40 +0100 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH] const / static (against current CVS) Message-ID: <20050824203540.GC31875@mail.shareable.org> References: <20050823174026.GA27203@rhlx01.fht-esslingen.de> <23bcb8700508240554653c7ff0@mail.gmail.com> <200508241441.45656.paul@codesourcery.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200508241441.45656.paul@codesourcery.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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