Page MenuHomeFreeBSD

ctl_ioctl.h: Do not abuse enums for bit fields of flags
AcceptedPublic

Authored by jhb on Wed, Feb 26, 3:54 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Mar 13, 2:25 PM
Unknown Object (File)
Wed, Mar 5, 4:14 AM
Unknown Object (File)
Tue, Mar 4, 8:46 AM
Unknown Object (File)
Tue, Mar 4, 12:18 AM
Unknown Object (File)
Tue, Mar 4, 12:11 AM
Unknown Object (File)
Mon, Mar 3, 10:57 PM
Unknown Object (File)
Mon, Mar 3, 10:02 PM
Unknown Object (File)
Mon, Mar 3, 5:09 PM
Subscribers

Details

Reviewers
asomers
imp
Group Reviewers
cam
Summary

C++ does not permit treating enum values as individual bits used with
the bitwise operators. For types that are a mask of flags, switch the
typedef to an unsigned int and use preprocessor macros for flag
constants.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 62636
Build 59520: arc lint + arc unit

Event Timeline

jhb requested review of this revision.Wed, Feb 26, 3:54 PM
This revision is now accepted and ready to land.Sat, Mar 15, 7:34 PM

This is a common pattern in CAM to make things more debuggable.

Why #define rather than done variation on const int foo = 0x1000; ?

In D49138#1126074, @imp wrote:

This is a common pattern in CAM to make things more debuggable.

Why #define rather than done variation on const int foo = 0x1000; ?

Oh, I just did #define since that is the most common way of doing constants in the tree. I would not be opposed to using const int.

In D49138#1126519, @jhb wrote:
In D49138#1126074, @imp wrote:

This is a common pattern in CAM to make things more debuggable.

Why #define rather than done variation on const int foo = 0x1000; ?

Oh, I just did #define since that is the most common way of doing constants in the tree. I would not be opposed to using const int.

The only reason we do the funky ENUM bit dance is so gdb prints symbolic values better.
If const int gives us that, that's a reason to use it. Otherwise, I'm neutral: I'm not dogmatically
opposed to cpp, and const int doesn't solve a real problem in this case when cpp dogma is
factored out. Maybe 'C++ custom" would be a reason enough to do it if we had a larger C++
developer community that adhered to that custom.

tl;dr: I'm good either way unless const int gives better debugging which I'm skeptical of now that I'm typing this out.