2020-08-22 03:41 PM
Hello,
What's the difference between the following 2 function calls ?
some_function ( & x ) ;
some_function ((uint8_t *)&x) ;
2020-08-22 04:04 PM
Technically in compiled code there is no difference. With this cast you are just telling the compiler that this conversion of different pointer types really is OK and there is no need for a warning. :)
2020-08-22 04:37 PM
Warning depends on how x is defined
2020-08-24 12:15 PM
So it should be used when x is a point - but IS NOT a pointer to uint8_t ?
The cast makes x to point to uint8_t - so there's no warning ?
2020-08-24 03:14 PM
Is is not clear from your case WHAT x is.
Probably shouldn't be a pointer because you're asking what address the variable is in memory, ie &x (Address of x)
uint32_t x;
some_function ((uint8_t *)&x) ; // casting the address of 32-bit value x, to a byte pointer