2021-11-03 08:27 AM
I ran into a warning for one section of code that I did not for a different section of code. So I simplified it into two function. I don't see why I get a warning for one and not the other.
void test32(uint32_t *data) {
uint32_t src_addr = (uint32_t) data;
}
void test16(uint16_t *data) {
uint16_t src_addr = (uint16_t) data;
}
The compiler complains (also about unused variables, but I removed those)
../Core/Src/main.c: In function 'test16':
../Core/Src/main.c:161:22: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
161 | uint16_t src_addr = (uint16_t) data;
| ^
The compiler appears to be based on gcc 9.3.1.
If I put these two functions in a simple C file and build it on straight Linux (gcc 9.3.0) the warning exists for both instances.
main.c: In function ‘test16’:
main.c:15:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
15 | uint16_t src_addr = (uint16_t) data;
| ^
main.c: In function ‘test32’:
main.c:20:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
20 | uint32_t src_addr = (uint32_t) data;
| ^
2021-11-03 08:29 AM
64-bit Linux? This would explain the difference.
hth
KnarfB
2021-11-03 08:31 AM
Yes, x64 linux. I don't understand the difference between the two variables types on stm32, and why that warning comes up.
2021-11-03 08:39 AM
sizeof a pointer is 8 bytes on a 64-bit Linux but 4 bytes on a 32-bit STM. Therefore test32 yields a the warning under Linux but not on STM (same size like uint32_t).
2021-11-03 08:41 AM
I see. It's the pointer size. Okay, thanks!
2021-11-03 10:08 AM
And for detail test16 is failure ... truncate part from pointer.