san wrote:
Hi,
I need to cast a void* to int.
I am doing the following
int sig = reinterpret_cast<int> (clientData);
where clientData is of type void*.
Its working well for 32-bit machine.
But giving error on 64-bit as
"Error: Cannot cast from void* to int."
What could be the reason..
Please help.
On a 64-bit machine void * is likely to be a 64-bit entity while an int
is probably still only 32-bit so your compiler refuses to do this
because the pointer would get truncated making it impossible to ever
get it back from the int.
If you _really_ do not care about truncation you could try
long long sig1 = reinterpret_cast<long long> (clientData);
int sig = static_cast<int>(sig1);