Hello,
I am just experimenting with some code. And I am not sure why I need to cast to an unsigned char*.
I get this error: cannot convert from 'unsigned char' to 'unsigned char *'
I can understand that the pointer is an unsigned char. But if I am assigning the address of the myFloat which I am casting a unsigned char. Why do I need to cast it as a pointer as well?
The following example using a int:Code:float myFloat = 10000; unsigned char *ptrChar; ptrChar = (unsigned char *) &myFloat; //Why can't I just do this? ptrChar = (unsigned char) &myFloat;
As the pointer is an int and I am assigning the address of myInt this works perfectly ok.Code:int myInt = 1000; int *ptrInt = &myInt;
However, with the example above I have converted to a unsigned char.
Many thanks for clearing this up.
Steve



LinkBack URL
About LinkBacks


