WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] Add -Wcast-qual flag

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: Re: [Xen-devel] [PATCH] Add -Wcast-qual flag
From: "Christoph Egger" <Christoph.Egger@xxxxxxx>
Date: Thu, 21 Dec 2006 12:12:31 +0100
Cc: Keir Fraser <keir@xxxxxxxxxxxxx>
Delivery-date: Thu, 21 Dec 2006 03:12:47 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <C1B01571.6AE9%keir@xxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: AMD / OSRC
References: <C1B01571.6AE9%keir@xxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: KMail/1.9.4
On Thursday 21 December 2006 11:41, Keir Fraser wrote:
> On 21/12/06 10:05, "Christoph Egger" <Christoph.Egger@xxxxxxx> wrote:
> > The xen-cast.diff adds the -Wcast-qual flag.
>
> We don't enable this flag precisely because we end up needing to scatter
> const all over the place like confetti.

That doesn't imply that this is bad. Compilers may generate better code.

> I'm not convinced that use of const improves code quality.

In my experience, exactly this will happen.

> I fear we'd end up with 'const foo * const bar' all  
> over the place -- ugly and confusing to most programmers (who frequently
> mess up const placement, in my experience).

Exactly these programmers will stop doing this, when the compiler tells them.


With -Wcast-qual you find code that does things like this:

     int foo(const char *str) {
          char *s = str;
          int i;
          ....
          s[i] = '\0';
     }

Modifying read-only memory is IMO never a good idea, in particular,
when it is shared with something else.

And there are indeed places in the xen code, where this happens.
(Example: Look how canonicalize() is used in tools/xenstored/*,
 Look at copy_to_user_hvm() in xen/arch/x86/hvm/platform.c )

Please have a closer look at the patches.




_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel