簡體   English   中英

在C預處理器中舍入

[英]Rounding in C Preprocessor

我在預處理器中定義了一些值。 例如

#define a 1000
#define b 0.5*a

當我嘗試在需要整數的地方使用b時,我得到一個錯誤。 我不想總是在我的代碼中使用b並在#define行中執行一次,這可能嗎?

試試這個:

#define a 1000
#define b (a/2)
#define b ((int)(a * 0.5))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM