Address to integer in C
I need help converting an address of a variable to an integer value. What I tried so far was casting the address as so: (int)(&variable). While it works, I want to find another way to do this without it giving a warning.
My guess is that `int` is not large enough to hold the value of the address, so you should use a sufficiently large data type like `uintptr_t`. You might be able to cast that to `int` without warning, but I don't know why you need to use an `int` in the first place.
&variable is an unsigned integer by itself. If you have a 64bit machine ( you can put more than 4GB of RAM in it ), it may be too large for the C int data type which is usually a signed 32bit integer ( the 31st bit is used for the sign so the maximum value is a little over 2 billion ). I believe that an unsigned long int data type will handle an address fine.
Join our real-time social learning platform and learn together with your friends!