Product Code Database
Example Keywords: grand theft -psp $21-116
barcode-scavenger
   » » Wiki: Void Type
Tag Wiki 'Void Type'.
Tag

Void type
 ( ) 

 C O N T E N T S 
Rank: 100%
Bluestar Bluestar Bluestar Bluestar Blackstar

The void type, in several programming languages, more so curly bracket programming languages derived from C and ALGOL 68, is the of a function that normally, but provides no result value to its caller. Usually such functions are called for their side effects, such as performing some task or writing to their input parameters. The use of the void in such context is comparable to procedures in Pascal and syntactic constructs which define subroutines in . It is also similar to the used in functional programming languages and type theory. See Unit type#In programming languages for a comparison.

C and C++ also support the void pointer (or pointer to void type), denoted void*, but this is an unrelated notion. Variables of this type are pointers to data of an unspecified type, so in this context (but not the others) void* acts roughly like a universal or ; it does not literally "point" to a void in memory. A program can convert a pointer to any type of data (except a ) to a pointer to void and back to the original type without losing information, which makes these pointers useful for polymorphic functions. The C language standard does not guarantee that the different pointer types have the same size or alignment.


In C and C++
A function with void result type ends either by reaching the end of the function or by executing a with no returned value. The void type may also replace the argument list of a function prototype to indicate that the function takes no arguments. Note that in all of these situations, void is not a type qualifier on any value. Despite the name, this is semantically similar to an implicit , not a zero or (which is sometimes confusingly called the "void type"). Unlike a real unit type which is a singleton, the void type lacks a way to represent its value and the language does not provide any way to declare an object or represent a value with type void.

In other C-derived languages, such as Java and C#, void exists similarly with the same use. While Java does not have explicit pointers, C# has void* inside of unsafe blocks.

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 to char. Some early C 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 such function calls to void to suppress this warning. By the time Bjarne Stroustrup began his work on C++ in 1979–1980, void and void* were part of the C language dialect supported by AT&T-derived compilers.

The explicit use of void vs. giving no arguments in a function prototype had different semantics in C and C++, as detailed in this table:

(2026). 9780321543721, Addison-Wesley.


(allowed since C23)
(preferred)
(allowed for backwards compatibility with C)
(until C23, accepts a constant but unknown number of arguments)(not strictly equivalent; this is a variadic template)

The C syntax to declare a (non-variadic) function with an as-yet-unspecified number of parameters, e.g. void f(); above, was deprecated in C99.Bjarne Stroustrup, C and C++: Case Studies in Compatibility. Reconcilable differences? You decide, Dr. Dobb's, September 01, 2002; print version In C23 (and C++), a function prototype with empty parentheses declares a function with zero parameters.

In C and C++, one can write a "void cast" to explicitly indicate to discard a value. void f(maybe_unused int a, int b) {

   (void)a;
   return b;
     
}


In Haskell
In contrast to C++, in the functional programming language , the void type denotes the , which has no inhabitants. A function into the void type does not return results, and a side-effectful program with type signature IO Void does not terminate, or crashes. In particular, there are no into the void type.

In functional programming, the would replace the use of the void type in C. This type has a unique result which provides no new information.


In Rust
In Rust's foreign function interface, there exists a std::ffi::c_void type equivalent to C/C++ void. There is no native void in Rust, as it uses the unit type ().


See also

Page 1 of 1
1
Page 1 of 1
1

Account

Social:
Pages:  ..   .. 
Items:  .. 

Navigation

General: Atom Feed Atom Feed  .. 
Help:  ..   .. 
Category:  ..   .. 
Media:  ..   .. 
Posts:  ..   ..   .. 

Statistics

Page:  .. 
Summary:  .. 
1 Tags
10/10 Page Rank
5 Page Refs
1s Time