Why does void in C mean not void?
- by Naftuli Tzvi Kay
In strongly-typed languages like Java and C#, void (or Void) as a return type for a method seem to mean:
This method doesn't return anything. Nothing. No return. You will not receive anything from this method.
What's really strange is that in C, void as a return type or even as a method parameter type means:
It could really be anything. You'd have to read the source code to find out. Good luck. If it's a pointer, you should really know what you're doing.
Consider the following examples in C:
void describe(void *thing)
{
Object *obj = thing;
printf("%s.\n", obj->description);
}
void *move(void *location, Direction direction)
{
void *next = NULL;
// logic!
return next;
}
Obviously, the second method returns a pointer, which by definition could be anything.
Since C is older than Java and C#, why did these languages adopt void as meaning "nothing" while C used it as "nothing or anything (when a pointer)"?