1

So I have (((uint32_t)(int32_t)IRQn) >> 5UL), where IRQn is an enum with range from -14 to 81.

From what I can see, it's first cast to int32_t, and then to uint32_t. Afterwards, it's shifted to left. Finally, it's used (outside of given code example) as an array index.

As a test, I wrote the following code and compiled it with the same compiler:

int a=0, b=0, c=0, d=0;

a=-5;
b=(int32_t)a;
c=(uint32_t)b;
d=(uint32_t)a;

From what I can see, all 4 numbers have the same binary value at the end. This leads me to belive that ((uint32_t)IRQn) would have worked as a cast as well.

So is there any other reason why we'd need to do the cast two times?

AndrejaKo
  • 1,721
  • 5
  • 25
  • 41

0 Answers0