From: David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Harvey Harrison
<harvey.harrison-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
Andrew Morton
<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
linux-arch <linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH 1/8] kernel: add common infrastructure for unaligned access
Date: Thu, 10 Apr 2008 23:01:04 +0100 [thread overview]
Message-ID: <11814.1207864864@redhat.com> (raw)
In-Reply-To: <1207864537.22001.47.camel@brick>
Harvey Harrison <harvey.harrison-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Actually, you probably _ought_ to have casts, but it should look like this:
> >
> > return (u16)p[0] | (u16)p[1] << 8;
>
> I've been looking at that thinking I needed something different, I
> believe it is ok as u8 will expand to int when shifted... correct? Or
> do I actually need the cast on each p[] term...anyone?
Hmmm... I think you may be right:
#include <stdio.h>
int main()
{
unsigned char x;
printf("%u, %u\n", sizeof(x), sizeof(x << 8));
return 0;
}
Says:
1, 4
In which case, the cast you do have is superfluous, and casting the retrievals
is unnecessary.
David
WARNING: multiple messages have this Message-ID (diff)
From: David Howells <dhowells@redhat.com>
To: Harvey Harrison <harvey.harrison@gmail.com>
Cc: dhowells@redhat.com, Andrew Morton <akpm@linux-foundation.org>,
linux-arch <linux-arch@vger.kernel.org>
Subject: Re: [PATCH 1/8] kernel: add common infrastructure for unaligned access
Date: Thu, 10 Apr 2008 23:01:04 +0100 [thread overview]
Message-ID: <11814.1207864864@redhat.com> (raw)
Message-ID: <20080410220104.vFSHR0OyWYOEYLFBP-pRx5BB58MMovNvkEhyci7MC2U@z> (raw)
In-Reply-To: <1207864537.22001.47.camel@brick>
Harvey Harrison <harvey.harrison@gmail.com> wrote:
> > Actually, you probably _ought_ to have casts, but it should look like this:
> >
> > return (u16)p[0] | (u16)p[1] << 8;
>
> I've been looking at that thinking I needed something different, I
> believe it is ok as u8 will expand to int when shifted... correct? Or
> do I actually need the cast on each p[] term...anyone?
Hmmm... I think you may be right:
#include <stdio.h>
int main()
{
unsigned char x;
printf("%u, %u\n", sizeof(x), sizeof(x << 8));
return 0;
}
Says:
1, 4
In which case, the cast you do have is superfluous, and casting the retrievals
is unnecessary.
David
next prev parent reply other threads:[~2008-04-10 22:01 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-10 19:44 [PATCH 1/8] kernel: add common infrastructure for unaligned access Harvey Harrison
2008-04-10 19:44 ` Harvey Harrison
2008-04-10 21:43 ` David Howells
2008-04-10 21:43 ` David Howells
[not found] ` <11527.1207863801-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-04-10 21:55 ` Harvey Harrison
2008-04-10 21:55 ` Harvey Harrison
2008-04-10 22:01 ` David Howells [this message]
2008-04-10 22:01 ` David Howells
[not found] ` <11814.1207864864-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-04-10 22:06 ` Harvey Harrison
2008-04-10 22:06 ` Harvey Harrison
2008-04-10 22:15 ` David Howells
2008-04-10 22:15 ` David Howells
[not found] ` <11907.1207865758-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-04-10 22:20 ` Harvey Harrison
2008-04-10 22:20 ` Harvey Harrison
2008-04-10 22:33 ` David Howells
2008-04-10 22:33 ` David Howells
[not found] ` <11989.1207866793-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-04-10 22:37 ` Harvey Harrison
2008-04-10 22:37 ` Harvey Harrison
2008-04-11 0:06 ` [PATCHv2 " Harvey Harrison
2008-04-11 0:06 ` Harvey Harrison
2008-04-11 18:09 ` Russell King
2008-04-11 18:09 ` Russell King
[not found] ` <20080411180928.GA9137-f404yB8NqCZvn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2008-04-11 19:01 ` Harvey Harrison
2008-04-11 19:01 ` Harvey Harrison
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=11814.1207864864@redhat.com \
--to=dhowells-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=harvey.harrison-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox