Implementation Notes

Function-like Macros

In general, function-like macros must behave exactly like regular functions. This means that all parameters to the macro must be evaluated as if they were normal function parameters even though they may be given as complex expressions from the caller.

Example: Bad implementation of set_bit()
 #define set_bit(nr, bitmap)    (bitmap[nr >> 5] |= 1 << (nr & 31))

 void foo(int a, int b)
 {
        set_bit(a | b, &foo_bitmap);
        set_bit(a++, &bar_bitmap);
 }

The preceding example has two problems:

For an example of a correct implementation, please see the set_bit() macro as it appears in the framework.

Generated on Thu Apr 29 14:09:42 2010 for uart-loopback by  doxygen 1.6.3