I am new to C++, I have a function which returns address of a memory location and I want to assign that address to a pointer, just like:
unsigned int address = 0xdeadbeef;
unsigned int* memory_ptr = (unsigned int*) address;
But above code is through warning:
cast to pointer from integer of difference size [-Wint-to-pointer-cast]
Is there anyway to do this task cleanly in C++ ?
Instead of unsigned int
you can use uintptr_t
.
Integer type capable of holding a value converted from a void pointer and then be converted back to that type with a value that compares equal to the original pointer.
User contributions licensed under CC BY-SA 3.0