liveBook · Manning

Void type

As explained in Modern C

The void type is the C type that represents the absence of a value and cannot directly form an object with a usable stored value.

In C, void represents the absence of a value. It appears in two function-prototype conventions: `void` as the parameter list means no arguments, while `void` as the return type means the function returns nothing usable. section 7.1

Two function-prototype uses

Read these declarations by separating syntax from meaning: `void main(void);` describes a function with no parameters, and `void swap_double(double *a, double *b);` describes a function whose result is absent. The prototype lets the compiler check calls against the declared parameter and return types. section 7.1

`void*` is different: it is a generic pointer to an existing object. Converting an object pointer to `void*` and back preserves the pointer value but removes the object's type information. Since a standalone `void` declaration cannot produce an object with a usable value, `void` variables should not be declared; `void*` should also be avoided when a typed pointer is available. section 12.4

How Modern C covers it

How deep it goes
Defines function conventions and void* conversions, then warns against void variables; it does not develop pointer mechanics further.
Examples
Uses main, swap_double, fbar, and object-pointer conversions to illustrate void's function and pointer roles.
What it assumes
Assumes familiarity with C declarations and pointers, while defining prototypes and object representation in context.
What you can do after
Apply it via C function declarations and object-pointer conversions, while avoiding void variables and unnecessary void* use.
How it connects
Connects void with function prototypes, object pointers, object representation, storage, type, and value.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.