开发者

Rounding in C Preprocessor

开发者 https://www.devze.com 2023-01-07 16:47 出处:网络
I am defining some values in the preprocessor. e.g. #defin开发者_运维技巧e a 1000 #define b 0.5*a

I am defining some values in the preprocessor. e.g.

#defin开发者_运维技巧e a 1000
#define b 0.5*a

When I try to use b in a place where integer is needed I get an error. I don't want to cast b always in my code and do it once in the #define line, is that possible?


Try this:

#define a 1000
#define b (a/2)


#define b ((int)(a * 0.5))
0

精彩评论

暂无评论...
验证码 换一张
取 消