Assertions
In order to simplify checks are make them stronger, add an #assert directive that triggers a compile error if the expression is false or any of the operands is undefined.
Example:
Code: Select all
#assert NUM_THREADS <= MAX_THREADS
Would replace:
Code: Select all
#if ! defined NUM_THREADS
#error "NUM_THREADS not defined"
#endif
#if ! defined MAX_THREADS
#error "MAX_THREADS not defined"
#endif
#if NUM_THREADS > MAX_THREADS
#error "(NUM_THREADS <= MAX_THREADS) is false"
#endif
This idea is courtesy of the HAL clock trees, mainly composed by pages and pages of such code where I spend a lot of fun time fixing errors.
Messages
Printing messages at compile time:
Code: Select all
#message "HSE clock frequency is: " STM32_HSE_CLK "Hz"
Note that macros are assumed to be integer expressions, the result is printed. If expansion is not complete or the expression is not correct then an error is printed instead replacing the whole "#message ...".
The message is printed as-is, without any prefix, and terminated by an EOL sequence.
Undefined Macros
No more assumption that undefined macros have a value of zero, it is an error, always.
Giovanni