Remove cast from constant in preprocessor

前端 未结 5 1911
醉酒成梦
醉酒成梦 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条回答
  •  梦毁少年i
    2021-01-12 18:57

    I know the issue thread is old, however I encountered it today... If you do not want to or cannot change the #define, the other answers are great, but if you have access to the #define, I recommend using for pre-processor operations (#if - #else - #endif) instead of:

    #define FLASH_BLOCK_SIZE ((uint8_t)64)
    

    use this define:

    #define FLASH_BLOCK_SIZE (64U)
    

    This way the cast is still there, and the compiler won't be "confused".

提交回复
热议问题