lkml.org 
[lkml]   [2007]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/19] unify desc_struct
Glauber de Oliveira Costa wrote:
> On Dec 6, 2007 6:54 PM, Andi Kleen <ak@suse.de> wrote:
>
>>> +/*
>>> + * FIXME: Acessing the desc_struct through its fields is more elegant,
>>> + * and should be the one valid thing to do. However, a lot of open code
>>> + * still touches the a and b acessors, and doing this allow us to do it
>>> + * incrementally. We keep the signature as a struct, rather than an union,
>>> + * so we can get rid of it transparently in the future -- glommer
>>> + */
>>> +#define raw_desc_struct struct { unsigned int a, b; }
>>> +#define detailed_desc_struct \
>>> + struct { \
>>> + u16 limit0; \
>>> + u16 base0; \
>>> + unsigned base1 : 8, type : 4, s : 1, dpl : 2, p : 1; \
>>> + unsigned limit : 4, avl : 1, l : 1, d : 1, g : 1, base2 :8;\
>>> + }
>>>
>> The standard clean way to do this is with a anonymous union.
>>
> It is an anonymous union.
>
> However:
>
> * It's an union of structs
> * I wished to keep the toplevel type as a struct
> The alternative would be to write:
>
> struct desc_struct {
> union {
> struct { unsigned int a, b; };
> struct {
> u16 limit0;
> u16 base0;
> unsigned base1 : 8, type : 4, s : 1, dpl : 2, p : 1;
> unsigned limit : 4, avl : 1, l : 1, d : 1, g : 1, base2 :8;
> };
> };
> };
>
> Which is fine, it's all the same in the end. Just with more shift
> rights, and more visual pollution.
>

No, that's much clearer. It's a pity that the anonymous struct/union
syntax isn't general enough to allow:

struct desc_packed {
u16 limit0;
u16 base0;
unsigned base1 : 8, type : 4, s : 1, dpl : 2, p : 1;
unsigned limit : 4, avl : 1, l : 1, d : 1, g : 1, base2 :8;
};

struct desc {
struct desc_packed;
};

J


\
 
 \ /
  Last update: 2007-12-06 23:05    [W:0.097 / U:0.504 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site