Re: bitwise enums

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

 



On Tue, Feb 20, 2018 at 11:00:37PM +0100, Luc Van Oostenryck wrote:
> On Tue, Feb 20, 2018 at 09:20:45AM -0800, Linus Torvalds wrote:
> > On Tue, Feb 20, 2018 at 9:02 AM, Luc Van Oostenryck
> > <luc.vanoostenryck@xxxxxxxxx> wrote:
> > > On Tue, Feb 20, 2018 at 08:09:39AM -0800, Matthew Wilcox wrote:
> > >> typedef __attribute__((bitwise)) enum {
> > >>       FOO,
> > >>       BAR,
> > >> } my_t;
> > >>
> 
> One detail about the syntax: my understanding of the attribute
> syntax is that in:
> 	typedef __bitwise enum foobar { FOO, BAR, } my_t;
> which is essentially the same as:
> 	enum foobar { FOO, BAR, };
> 	typedef __bitwise enum foobar my_t;
> the attribute relate to the typedef/my_t and not to the enum type.

Yes, I was worrying about that a little myself.

> It doesn't matter much later, when my_t is used, but it matters
> for the initializers, for example in:
> > >> typedef __attribute__((bitwise)) enum {
> > >>       FOO = 1,
> > >>       BAR = 2,
> > >>       BAZ = 4,
> > >>       QUUX = 8,
> > >>       WIBBLE = 0x10,
> 
> So, I propose that what we should aim for is to support:
> 	enum __bitwise foobar { FOO, BAR, };
> and, maybe:
> 	enum foobar { FOO, BAR, } __bitwise;
> Both are equivalent following GGC's attribute's syntax but in
> this case, I think the first is far better (and is easier).

I like your first option better than your second.  From my point of view,
it's just swapping two words around:

typedef __bitwise enum {

to

typedef enum __bitwise {

(I understand from a syntactic analysis point of view, it has a completely
different meaning ;-)
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux