Converting double to void* in C

On many systems a double is 8 bytes wide and a pointer is 4 bytes wide. The former, therefore, would not fit into the latter. You would appear to be abusing void*. Your solution is going to involve allocating storage space at least as big as the largest type you need to store in some … Read more

Casting void pointers

Your own explanation is the right one. Pre-ANSI C (‘K&R’ C) did not have a void * type with implicit conversion. char * doubled as a pseudo void * type, but you needed the explicit conversion of a type cast. In modern C the casting is frowned upon because it can suppress compiler warnings for … Read more

can void* be used to store function pointers? [duplicate]

Maybe. Until C++11, they couldn’t; but C++11 adds: Converting a function pointer to an object pointer type or vice versa is conditionally-supported. The meaning of such a conversion is implementation-defined, except that if an implementation supports conversions in both directions, converting a prvalue of one type to the other type and back, possibly with different … Read more

How to cast an integer to void pointer?

This is a fine way to pass integers to new pthreads, if that is what you need. You just need to suppress the warning, and this will do it: #include <stdint.h> void *threadfunc(void *param) { int id = (intptr_t) param; … } int i, r; r = pthread_create(&thread, NULL, threadfunc, (void *) (intptr_t) i); Discussion … Read more

C isn’t that hard: void ( *( *f[] ) () ) ()

There is a rule called the “Clockwise/Spiral Rule” to help find the meaning of a complex declaration. From c-faq: There are three simple steps to follow: Starting with the unknown element, move in a spiral/clockwise direction; when ecountering the following elements replace them with the corresponding english statements: [X] or [] => Array X size … Read more