lkml.org 
[lkml]   [2013]   [Nov]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 03/22] tools lib traceevent: Add traceevent_host_bigendian function
Date
Hi Steve,

On Sat, 23 Nov 2013 03:27:08 -0500, Steven Rostedt wrote:
> On Fri, 22 Nov 2013 23:22:52 +0900
> Namhyung Kim <namhyung@kernel.org> wrote:
>
>> 2013-11-21 (목), 12:01 +0100, Jiri Olsa:
>> > Adding traceevent_host_bigendian function to get host
>> > endianity. It's used in following patches.
>>
>> [SNIP]
>> > +static inline int traceevent_host_bigendian(void)
>> > +{
>> > + unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
>> > + unsigned int *ptr;
>> > +
>> > + ptr = (unsigned int *)str;
>> > + return *ptr == 0x01020304;
>>
>> Is it safe for every architecture supported - especially ones that
>> require stricter alignment? I know many architectures/compilers align
>> stack but not sure doing this is safe for all architecture.
>
> Would you prefer this (I tested it on both a big and little endian)
>
> {
> unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
> unsigned int val;
>
> memcpy(&val, str, 4);
> return val == 0x01020304;
> }

Yeah, looks good to me.

Thanks,
Namhyung
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2013-11-25 08:41    [W:0.139 / U:2.852 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site