-
pointer type casting
hi all,
Code:
typedef unsigned int uint32
typedef unsinged short uint16
typedef unsinged char uint8
...
...
uint8* data;
uint32 source;
*(uint32*)data=(uint32)source;
why would this code give the following error
"invalide operands of type "int" and "uint32*" to binary 'operator*' " ?
thank you in advance
-
1) casting source to uint32 is useless since it's an uint32 already
2) casting data (uint8*) to uint32* then trying to assign a value will write 3 bytes outside the valid range (DANGER!)
3) data isn't pointing at anything valid (DANGERx2!)
4) You should use static_cast and reinterpret_cast instead of the old C-style casts
What exactly are you trying to do?