B
bwaichu
What is the best way to handle this warning:
warning: cast from pointer to integer of different size
I am casting in and out of a function that requires a pointer type. I
am casting an integer as a pointer, but the pointer is 8 bytes while
the integer is only 4 bytes.
Here's an example function:
pthread_create(&tid, NULL, readit, (void *)(long)connfd)
I need to pass the file descriptor as a void * for pthread_create. But
I
need the file descriptor as an integer to read and write to it. Is the
above the best approach to turn off the warning? I am considering just
typecasting to size_t before typecasting to the pointer. Is that a
better
approach than typecasting to long since size_t should remain equal to
the size of pointers?
Of course, I run into the reverse problem when I have to close the
file descriptor.
close((int) arg);
I don't even know what to do in the above case. I shouldn't be
truncating
anything, so I should be okay.
I originally wrote the code using a 32 bit version, so I am receiving
these errors
when I ported it over to a 64 bit version.
Thanks!
warning: cast from pointer to integer of different size
I am casting in and out of a function that requires a pointer type. I
am casting an integer as a pointer, but the pointer is 8 bytes while
the integer is only 4 bytes.
Here's an example function:
pthread_create(&tid, NULL, readit, (void *)(long)connfd)
I need to pass the file descriptor as a void * for pthread_create. But
I
need the file descriptor as an integer to read and write to it. Is the
above the best approach to turn off the warning? I am considering just
typecasting to size_t before typecasting to the pointer. Is that a
better
approach than typecasting to long since size_t should remain equal to
the size of pointers?
Of course, I run into the reverse problem when I have to close the
file descriptor.
close((int) arg);
I don't even know what to do in the above case. I shouldn't be
truncating
anything, so I should be okay.
I originally wrote the code using a 32 bit version, so I am receiving
these errors
when I ported it over to a 64 bit version.
Thanks!