void*从内存的角度来看,将整数值转换为或者反之亦然?我的理解是void*一个未指定长度的内存块的地址.
这似乎就像比较苹果和橙子.
int myval = 5;
void* ptr = (void*)myval;
printf("%d",(int)ptr);
Run Code Online (Sandbox Code Playgroud)
我意识到我应该给出使用它的确切上下文.
int main(int argc, char* argv[]) {
long thread; /* Use long in case of a 64-bit system */
pthread_t* thread_handles;
/* Get number of threads from command line */
if (argc != 2) Usage(argv[0]);
thread_count = strtol(argv[1], NULL, 10);
if (thread_count <= 0 || thread_count > MAX_THREADS) Usage(argv[0]);
thread_handles = malloc (thread_count*sizeof(pthread_t));
for (thread = 0; thread < thread_count; thread++)
pthread_create(&thread_handles[thread], NULL, Hello, (void*) thread); …Run Code Online (Sandbox Code Playgroud)