Re: bitwise enums

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

 



On Tue, Feb 20, 2018 at 04:47:03PM -0800, Linus Torvalds wrote:
> On Tue, Feb 20, 2018 at 4:06 PM, Luc Van Oostenryck
> <luc.vanoostenryck@xxxxxxxxx> wrote:
> >
> > I'm not 100% sure I understand the problem (if problem there is).
> > For the typedef, yes it's how it's used for __le32 or gfp_t because
> > we want to combine __bitwise with int to create a new, distinct type.
> > But here, we don't care about the typedef because we don't need one
> > since we're creating a new, distinct type anyway: the enum itself.
> 
> Yes, but think of it this way.. Imagine that you do:
> 
>         typedef enum __bitwise foobar { FOO, BAR, } my_t;
> 
> and now those constant FOO and BAR are a bitwise enum, and compatible
> with "my_t". That's what we're aiming for, right?
> 
> What happens if we then do
> 
>         typedef enum __bitwise foobar another_t;
> 
> which is *another* type of the same base type?

OK, I understand now.

> I personally think that the _constants_ (FOO and BAR) should be
> compatible with _both_ types, but a variable of type "my_t" should not
> mix with a variable of type "another_t".

Well, I think that in this case another_t should just be
another name for the type 'enum __bitwise foobar' and so
variables of type "my_t" may freely mix with others of type
"another_t". But that's mainly becayse in this case the __bitwise
is attached to the enum and not to the typedef, as it's
usually done for __bitwise.

An even more annoying case would be:
	typedef __bitwise enum __bitwise foobar weird_t;
or
	typedef __bitwise enum foobar weird_t;
and in this case weird_t should be incompatible with 'enum foobar'.
But maybe we should make this invalid.


Also, just to be clear, I think that after we have declared
	enum __bitwise foobar { ... };
variables of this type can then be declared with:
	enum foobar var
because the __bitwise is part now of the type which in
the code can be accessed with the words 'enum foobar'.
Exactly like a type declared as:
	struct __packed s { ...}
or
	struct s { ... } __packed;
can have variables of this type declared with
	struct s var;


> I dunno. Maybe this is not worth worrying about.

Yes, I think so too. I'll add some documentation, including for
limitations and the corner cases.

-- Luc
--
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