From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Thomas Wood <thomas.wood@intel.com>
Cc: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH i-g-t 2/2] tests/gem_pwrite_snooped: fix const cast warning
Date: Mon, 7 Sep 2015 18:18:36 +0300 [thread overview]
Message-ID: <20150907151836.GA29811@intel.com> (raw)
In-Reply-To: <CANkqdn0PXEc5YkuGuy-SHYALww1hngy5ML3VKaP5Rt-JOBbiBA@mail.gmail.com>
On Mon, Sep 07, 2015 at 03:49:58PM +0100, Thomas Wood wrote:
> On 7 September 2015 at 13:53, Ville Syrjälä
> <ville.syrjala@linux.intel.com> wrote:
> > On Mon, Sep 07, 2015 at 12:34:12PM +0100, Thomas Wood wrote:
> >> Signed-off-by: Thomas Wood <thomas.wood@intel.com>
> >> ---
> >> tests/gem_pwrite_snooped.c | 4 ++--
> >> 1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/tests/gem_pwrite_snooped.c b/tests/gem_pwrite_snooped.c
> >> index d3f6223..29142c3 100644
> >> --- a/tests/gem_pwrite_snooped.c
> >> +++ b/tests/gem_pwrite_snooped.c
> >> @@ -76,14 +76,14 @@ static void blit(drm_intel_bo *dst, drm_intel_bo *src,
> >> intel_batchbuffer_free(batch);
> >> }
> >>
> >> -static void *memchr_inv(const void *s, int c, size_t n)
> >> +static void const *memchr_inv(const void *s, int c, size_t n)
> >
> > Oh, and I'll just note that I wrote it the way I did orignally so that
> > it matches memchr(). But I suppose matching memchr() exactly is not all
> > that important.
>
> It may actually be more useful to remove const from the function
> parameter rather than add it to the return type.
The function doesn't change the data, so passing in const definitely
makes sense. I guess it could also use __attribute__((pure))
> Other than adding or
> removing the const annotations, there doesn't seem to be any other way
> of avoiding the warning from -Wcast-qual in this case.
Would be nice if we could have const and non-const versions of the
function, so that the constness of the returned type depends on what
gets passed in. But this is C and not C++ so we can't have that. And
even in C++ you would then have to make the function argument to
non-const as well, which loses the information that it doesn't change
the data.
>
>
> >
> >> {
> >> const unsigned char *us = s;
> >> unsigned char uc = c;
> >>
> >> while (n--) {
> >> if (*us != uc)
> >> - return (void *) us;
> >> + return (void const *) us;
> >> us++;
> >> }
> >>
> >> --
> >> 1.9.1
> >>
> >> _______________________________________________
> >> Intel-gfx mailing list
> >> Intel-gfx@lists.freedesktop.org
> >> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
> >
> > --
> > Ville Syrjälä
> > Intel OTC
--
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2015-09-07 15:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-07 11:34 [PATCH i-g-t 1/2] build: fix unused-result warnings Thomas Wood
2015-09-07 11:34 ` [PATCH i-g-t 2/2] tests/gem_pwrite_snooped: fix const cast warning Thomas Wood
2015-09-07 12:51 ` Ville Syrjälä
2015-09-07 12:53 ` Ville Syrjälä
2015-09-07 14:49 ` Thomas Wood
2015-09-07 15:18 ` Ville Syrjälä [this message]
2015-09-08 10:25 ` [PATCH i-g-t] tests/gem_pwrite_snooped: disable " Thomas Wood
2015-09-09 18:19 ` [PATCH i-g-t 1/2] build: fix unused-result warnings Zanoni, Paulo R
2015-09-10 10:47 ` [PATCH i-g-t] lib: don't use igt_warn in signal handlers Thomas Wood
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=20150907151836.GA29811@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=thomas.wood@intel.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.