I am working on converting many C programs from Unix to Linux and this free() syntax caught my attention:
free((char *) area );
What's the difference between this and free( area ); ?
The signature of free is:
void free(void *ptr);
So if area is a pointer type that is returned by malloc or its cousins, the conversion in free((char *) area ); is pointless.
Unless... if the code is really, really old, that is, before ANSI C introduced void * as generic pointer.  In that ancient time, char * is used as generic pointer.
If someone were storing a pointer to dynamic allocated data in a non-pointer type sanctioned by the standard, i.e. area  is declared as intptr_t for example, this casts the non-pointer to a pointer type and allows it to be freed.
If area is already a pointer type, this makes no sense at all with any C code written in the last quarter-century.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With