-
Pointer initialization
Hello all,
I need to initialize a pointer variable with a knowing address. Please see code below, ptr is the final destination and value of ptr_address contains the address value, so I need to do something like ptr = *ptr_address.
Code:
int *ptr;
int *ptr_address;
int address;
address = 0x10000005;
ptr_address = &(address);
ptr = *ptr_address;
The problem is that compiler gives the following warning message:
warning: assignment makes pointer from integer without a cast [enabled by default]
Is my code wrong or there is any other way to do it without receiving this compiler warning?
Thanks.
-
The value can be cast to be a pointer to integer:
ptr = (int *)0x10000005;
-
Hi rcgldr, the problem is that i can't use direct value because address comes as a variable value, so I need use this variable.
I've already tried ptr = *((int *) ptr_address); but warning is the same.
-
ptr = (int *)*ptr_address