-
Pointer variables
I have a question about pointers. I want to take the address stored in a pointer and store it in an unsigned char... yeah, it's not big enough, i know, but it works for what im doing i think. Only problem is, everything I try yields the wrong result. I have two variables, ip and main_mem, both unsigned chars:
Code:
*ip = (unsigned char *) *main_mem + 1;
and then I tried:
Code:
memcpy ((unsigned char *) ip, (unsigned char *) main_mem);
So if this doesn't work, how do i do it? If more source is needed or if anyone wants an explanation, let me know. Thanks guys!!!
-
Aside from it being a stupid thing to do, this should work:
Code:
unsigned char c;
int *p;
c = (unsigned char)p;
You could also, if you want to use memcpy() do:
Code:
memcpy(&c, p, sizeof(unsigned char));
However, depending on the byte-ordering (little endian or big endian) you may get "the wrong end" of the pointer that way.
--
Mats