Ask your own question, for FREE!
Computer Science 11 Online
OpenStudy (anonymous):

Address to integer in C

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

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.

OpenStudy (rsmith6559):

&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.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!