3 ms·
Another trap with macros is that they might introduce extremely hard to detect bugs. You macro for clearing a bit like for example: #define CLEARBIT(a,p) = (
by raxxorraxor 5y ago
Another trap with macros is that they might introduce extremely hard to detect bugs. You macro for clearing a bit like for example:
#define CLEARBIT(a,p) = ((a) &= ~(1 << (p)))
might not work correctly if your datatype is something "exotic" like a long. An inlined function might be the better choice.
Otherwise you would need to define specific macros again:
#define CLEARBITLONG(a,p) = ((a) &= ~(1L << (p)))
These bugs can steal hours of your time, especially on embedded systems where debugging is less accessible.
- FrozenVoid 5y ago#define CLEARBIT(a,p) = ((a) &= ~((typeof(a))1 << (p)))
- raxxorraxor 5y agoThat is clearly better provided the compiler supports it. Less portable but it should really be a part of ISO C in my opinion.