Rounding in C-preprocessor

I define some values ​​in the preprocessor. eg.

#define a 1000
#define b 0.5*a

When I try to use b in a place where an integer is required, I get an error. I don’t want to balways include it in my code and do it once per line #define, is this possible?

+3
source share
2 answers

Try the following:

#define a 1000
#define b (a/2)
+4
source
#define b ((int)(a * 0.5))
+3
source

Source: https://habr.com/ru/post/1755274/


All Articles