On core_cm4.h why is there casting like ((uint32_t)(int32_t)IRQn)?

前端 未结 3 1626
眼角桃花
眼角桃花 2021-01-14 08:52

In the following code from core_cm4.h why is there a double cast ((uint32_t)(int32_t)IRQn)?

For example in the following function:

__STA         


        
3条回答
  •  无人及你
    2021-01-14 09:22

    Assuming IRQn is an integer (any signed integer type) in the range you say, then (uint32_t)(int32_t)IRQn is exactly the same as (uint32_t)IRQn.

    The author of the code possibly didn't understand C type conversion rules; which are based on values, not representations. Converting -3, for example, to uint32_t always gives UINT32_MAX - 2 regardless of which data type the -3 was. It's the value of "negative 3" that matters.

    (The other answer explains the difference between using a cast and no cast at all).

提交回复
热议问题