All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christoph Egger" <Christoph.Egger@amd.com>
To: xen-devel@lists.xensource.com
Cc: Keir Fraser <keir@xensource.com>
Subject: Re: [PATCH] Add -Wcast-qual flag
Date: Thu, 21 Dec 2006 12:12:31 +0100	[thread overview]
Message-ID: <200612211212.31700.Christoph.Egger@amd.com> (raw)
In-Reply-To: <C1B01571.6AE9%keir@xensource.com>

On Thursday 21 December 2006 11:41, Keir Fraser wrote:
> On 21/12/06 10:05, "Christoph Egger" <Christoph.Egger@amd.com> 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.

  reply	other threads:[~2006-12-21 11:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-21 10:05 [PATCH] Add -Wcast-qual flag Christoph Egger
2006-12-21 10:41 ` Keir Fraser
2006-12-21 11:12   ` Christoph Egger [this message]
2006-12-21 12:51   ` Jan Beulich
2006-12-21 13:25     ` Christoph Egger
2006-12-21 13:28     ` Keir Fraser
2006-12-21 14:18       ` Jan Beulich
2006-12-21 14:56         ` Christoph Egger

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=200612211212.31700.Christoph.Egger@amd.com \
    --to=christoph.egger@amd.com \
    --cc=keir@xensource.com \
    --cc=xen-devel@lists.xensource.com \
    /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.