cancel
Showing results for 
Search instead for 
Did you mean: 

Pointer casting during function call

skon.1
Senior

Hello,

What's the difference between the following 2 function calls ?

some_function ( & x ) ; 
some_function ((uint8_t *)&x) ;

4 REPLIES 4
Piranha
Chief II

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. :)

Warning depends on how x is defined

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
skon.1
Senior

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 ?

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..