[NO REPLY] The Preprocessor (rev #2, 2018-1-15)

A place of insane ideas, nothing to see here.
User avatar
Site Admin
Posts: 14465
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1080 times
Been thanked: 924 times

[NO REPLY] The Preprocessor (rev #2, 2018-1-15)

Postby Giovanni » Sun Dec 10, 2017 5:24 pm

Ideas regarding the preprocessor:


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.


Code: Select all


Would replace:

Code: Select all

#if ! defined NUM_THREADS
#error "NUM_THREADS not defined"
#if ! defined MAX_THREADS
#error "MAX_THREADS not defined"
#error "(NUM_THREADS <= MAX_THREADS) is false"

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.


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.


Return to “Safer C”

Who is online

Users browsing this forum: No registered users and 1 guest