I have a function with prototype
void* myFcn(void* arg) which is used as the starting point for a pthread. I need to convert the argument to an int for later use:
int x = (int)arg;
The compiler (GCC version 4.2.4) returns the error:
file.cpp:233: error: cast from 'void*' to 'int' loses precision
What is the proper way to cast this?
You can cast it to an
intptr_t type. It's an
int type guaranteed to be big enough to contain a pointer. Use
#include <cstdint> to define it.