Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 3.5: bitfields and basic types
#2
ISO C states that the only valid type for bitsets is int, unsigned int and signed int. Using char or long is implementation-defined behavior. And if you use uint32_t, you are most likely using \"typedef unsigned long uint32_t\", and unsigned long in bit-fields isn't covered by ISO C.

---

My personal opinion of the best way to comform with the bit-field rules is to forbid the usage of bit-fields entirely for your applications. Bit-fields are poorly defined by the standard and have plenty of various undefined- and implementation-defined behavior, making them a big hazard for the safety of the program. And they are completely redundant: you don't need to use them as the bitwise operators do the very same thing: they work on a byte level theoretically, but a good compiler translates bitwise operations to bit-level instructions, making bit-fields pointless.


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)