Void type
From Wikipedia, the free encyclopedia
The void type, in several programming languages derived from C, is the type for the result of a function that produces no direct result. Usually such functions are called for their side effects, much like subroutines in Visual Basic and procedures in Pascal. A function with void result type ends either by reaching the end of the function or by executing a return statement with no returned value. In C, the void type also appears in the argument lists of function prototypes to indicate that the function takes no arguments. In all of these situations, the void type serves as a unit type. The language does not allow the use of the void type in variable declarations.
C and C++ also support the type pointer to void (specified as "void *"), which despite the name has little to do with the other uses of void. Variables of this type are pointers to data of an unspecified type, so in this context (but not the others) void acts as a universal or top type. A program can convert a pointer to any type of data to a pointer to void and back to the original type without losing information, which makes these pointers useful for polymorphic functions.
The void type is a product of Standard C. In earlier versions of C, functions with no specific result defaulted to a return type of "int" and functions with no arguments simply had empty argument lists. Pointers to untyped data were declared as integers or pointers to "char". Some early C compilers had the feature, now seen as an annoyance, of generating a warning on any function call that did not use the function's returned value. Old code sometimes casts such function calls to void to suppress this warning.