- Void type
The void type, in several programming languages derived from C and Algol68, 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 areturn statement with no returned value. In C, the void type also appears in the argument lists offunction prototype s to indicate that the function takes no arguments. Note that despite the name, in all of these situations, the void type serves as aunit type , not as a zero orbottom type . The language does not provide any way to declare an object or represent a value with typevoid
.C and
C++ also support the type "pointer to void" (specified asvoid *
), which has little to do with the other uses of void. Variables of this type arepointer s to data of an unspecified type, so in this context (but not the others) void acts as a universal ortop 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.In the earliest 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 tochar
. Some early Ccompiler s 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. By the timeBjarne Stroustrup began his work onC++ in 1979-1980, void and void pointers were part of the C language dialect supported by AT&T-derived compilers. [http://cm.bell-labs.com/cm/cs/who/dmr/chist.html, "Standardisation."]References
Wikimedia Foundation. 2010.