lkml.org 
[lkml]   [2008]   [Aug]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch] Add helper macros for little-endian bitfields
David Vrabel wrote:
> Al Viro wrote:
>
>> On Sun, Aug 24, 2008 at 06:37:43PM -0700, Roland Dreier wrote:
>>
>>> > + * NOTE: When using multibyte bitfields, you need to convert the data
>>> > + * from Little Endian to CPU before you can access the bitfield
>>> > + * (to make it simpler):
>>>
>> NOTE: When tempted to use multibyte bitfields on fixed-layout data, you
>> need to look in the mirror, ask yourself "what will they do to me during
>> code review for that?", shudder and decide that some temptations are
>> just not worth the pain.
>>
>
> But why is this worthy of a crispy flaming? I've not seen anything
> definite beyond a somewhat vague 'some compilers don't optimize
> bitfields very well'.
>
> The structure definition and the DECL_BF_LEx() macros might be ugly but
> the code using the structures is clearer. For example,
>
> get_random_bytes(&tiebreaker, sizeof(unsigned));
> drp_ie->tiebreaker = tiebreaker & 1;
>
> versus
>
> get_random_bytes(&tiebreaker, sizeof(unsigned));
> drp_ie->drp_control |= (tiebreaker & 1)
> ? UWB_DRP_IE_DRP_CTRL_TIEBREAKER : 0;
>

Why not just

drp_ie->drp_control |= tiebreaker & UWB_DRP_IE_DRP_CTRL_TIEBREAKER;

then? Doesn't matter which random bit you pick, does it?

J


\
 
 \ /
  Last update: 2008-08-27 23:23    [W:0.051 / U:1.868 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site