3.5 void Type

The void type is an incomplete type that cannot be completed.

The void type has three important uses:

The following example shows how void is used to define a function, with no parameters, that does not return a value:

void message(void)
{
  printf ("Stop making sense!");
}

The next example shows a function prototype for a function that accepts a pointer to any object as its first and second argument:

void memcopy (void *dest, void *source, int length);

A pointer to the void type has the same representation and alignment requirements as a pointer to a character type. The void * type is a derived type based on void .

The void type can also be used in a cast expression to explicitly discard or ignore a value. For example:

int tree(void);

void main()
{
  int i;

  for (; ; (void)tree()){...}  /* void cast is valid                  */

  for (; (void)tree(); ;){...} /* void cast is NOT valid, because the */
                               /* value of the second expression in a */
                               /* for statement is used               */

  for ((void)tree(); ;) {...}  /* void cast is valid                  */

}

A void expression has no value, and cannot be used in any context where a value is required.


Previous Page | Next Page | Table of Contents | Index