Can someone explain this line of c++ code using reinterpret_cast?

  • A+
Category:Languages

Consider (1):

 uint8_t *pUART = reinterpret_cast<uint8_t*>(0x0800); 

I know (1) simply changes the pUART pointer to 0x0800, but i'm confused how this way of doing it works.

It would make sense if it was (2):

 uint8_t* pUART = reinterpret_cast<uint8_t*>(0x0800); 

Im confused because the (1) is the same as (3):

 uint8_t x = reinterpret_cast<uint8_t*>(0x0800); 

but the compiler does not accept this. Can someone clear this up for me? Why does (1) work but not (3).


C++ is a tokenised language. That means whitespace does not matter, except where necessary to separate tokens.

uint8_t *pUART and uint8_t* pUART mean exactly the same thing. They are three tokens, namely uint8_t, *, and pUART.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: