Re: [PATCH 1/8] kernel: add common infrastructure for unaligned access

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Harvey Harrison <harvey.harrison@xxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-arch" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux