Garrett D'Amore writes: > I have macros like those above, yes. (Although in my code it looks more > like this:) > > #define BIT(x) (1UL << (x)) > ... > #define MYMASK BIT(4)
I'm surprised nobody's mentioned C structures with bit fields. I've used those to good effect on hardware in the past. (Yes, getting the access width right, particularly on writes, can be a pain on some devices.) > What I'm not sure about is the __SHIFTIN, __SHIFTIN, and __BITS(a,b) > forms that jmcp referred to. I don't see a lot of value in them -- > possibly because I don't use them enough that they are automatically > familiar and obvious to me. In the few cases I've had to do something like that, I've just set up a careful sequence of #defines and didn't look back: #define MUMBLE_BITS 0xe0000000u #define MUMBLE_SHIFT 29 #define FROTZ_BITS 0x1f000000u #define FROTZ_SHIFT 24 ... In general, they're not moving around so much over time that having special accessor macros is all that interesting, and I like to be able to look at the actual hex values at a glance to see where there might be missing or unaligned fields -- rather than counting out the bits on fingers and toes. So, I can't see a reason to argue against these new macros, but also not much reason I'd be interested in using them, either. -- James Carlson, Solaris Networking <[EMAIL PROTECTED]> Sun Microsystems / 35 Network Drive 71.232W Vox +1 781 442 2084 MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677 _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code