开发者

Rounding in C Preprocessor

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜