Skip to main content
skon.1
Associate III
August 22, 2020
Question

Pointer casting during function call

  • August 22, 2020
  • 3 replies
  • 919 views

Hello,

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

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

This topic has been closed for replies.

3 replies

Piranha
Principal III
August 22, 2020

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

Tesla DeLorean
Guru
August 22, 2020

Warning depends on how x is defined

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
skon.1
skon.1Author
Associate III
August 24, 2020

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 ?

Tesla DeLorean
Guru
August 24, 2020

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 VenmoUp vote any posts that you find helpful, it shows what's working..