Remove cast from constant in preprocessor

前端 未结 5 1906
醉酒成梦
醉酒成梦 2021-01-12 18:48

Background

In a microcontroller code, I am using a library provided by the producer where there are many constants defined. I\'m trying to give an error if there\'

5条回答
  •  粉色の甜心
    2021-01-12 19:09

    For any typedef you can get arrount this by changing to

    #define FLASH_BLOCK_SIZE ((uint8_t)+64)
    

    notice the little plus in there?

    The preprocessor replaces the typename it doesn't know anything about by 0, so this works out in both contexts. (The preprocessor is supposed to do all arithmetic in [u]intmax_t, anyhow)

    For the actual type you are using all of this makes not much sense. There is no such thing as a uint8_t constant. As soon they are evaluated all expressions of a type that is narrower than int are converted to int. So it probably doesn't makes any difference.

提交回复
热议问题