
void - type, specifier-type and a keyword in the programming languages C, C + +, Java, C # and D, borrowed from their common predecessor ALGOL 68.
History
Among the modern programming languages void keyword first appeared in C + + to support the concept of generalized indexes. Nevertheless, thanks to an early borrowing from C + +, the first legal document containing the keyword has become a standard C language, published by ANSI in 1989. As part of the language C + + void was standardized in 1998.
Subsequently, the keyword void, and the related linguistic constructions were inherited languages of Java and C #, D.
Syntax
Syntax, void is a type specifiers that are members of the broader group of specifiers ads.
Semantics
The semantics of the keyword void is not subject to the overall semantics of type specifiers and depends on the mode of use:
In the name of the type of values returned by function: an indication that the function does not return values, and call such a function is a void-expression. The body of such a function should not contain the operators return to the expressions. For example:
void f ();
In the deklaratora functions: indicates that the function has a prototype and has no parameters. For example:
int f (void);
In the name of a trust type of operation to bring: a void-alignment means abandoning the values given expression. For example:
# define promote_ptr () ((void) (ptr + +))
In the name of the type of void-pointer: the pointer is able to represent the values of any pointers to the object and incomplete types, ie addresses of all facilities. Thus, void-pointer is a generic object pointer. void-pointers are not able to represent the values of pointers to functions. Except in the case of bringing a constant null-pointer to a pointer to a function in C, explicit and implicit transformation between void-pointers and pointers to functions there.
Type void is defined as an incomplete type that can not be completed. As a consequence, this type should not be used where allowed only full types, such as the type parameter in the definition of functions.
The C language before the introduction of void
Before the publication of the first C standard in 1989. To put into language the keyword void, it was common practice to declare functions that do not return values without using the type specifiers. While such an announcement was semantically equivalent to the definition of the function returns a value of type int, intentionally omitted type specifiers emphasized that the function does not return any specific value. For example:
f (long l)
(
/ * ... * /
)
Similarly, the functions with no parameters were recorded with empty parentheses:
int main ()
(
/ * ... * /
)
As a generalized index using a pointer to char. Moreover, today's standards require that the representation and alignment requirements for void-pointers were the same as for pointers to char, which means that the interchangeability of these types.
First the standard dialect of C (C89), although it has allowed the recording to the keyword void, yet allow such use of implicit int in order to support compatibility with existing code. The modern dialect of C (C99) does not allow type specifiers otstutsviya names and types of ads.
0 коммент.:
Отправить комментарий