+ 3
Im not from a c background but somthing tells me this is a generic pointer it can point to anything in memory whether that's objects,Strings,ints ect.. but I assume you have to cast it before its used for type safety as computers are very stupid đŸ€·â€â™‚ïž.
1st Feb 2021, 1:34 PM
D_Stark
D_Stark - avatar
+ 2
To add, void pointers are practical when you need a generic interface to manipulate data of any type. An example is the comparison function you'd pass as an argument to qsort(). And you don't need to typecast void pointers; they're implicitly promoted to the correct type. The exception is if you're doing pointer arithmetic, casting to non-const, adding another level of indirection, or when passing it as an argument to a variadic function, like printf(). The typecasts for malloc(), calloc(), and realloc() is a C++ism - where pointer types are implicitly type-promoted to a void pointer, but not back. The superfluous casts for pointers to void are widely regarded as bad style in C and should be avoided.
1st Feb 2021, 4:59 PM
Mike A
Mike A - avatar