| 1 |
.\" Copyright 2020, Michael Kerrisk <[email protected]> |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH void 3type 2026-02-08 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
void \- abstract type |
| 9 |
.SH SYNOPSIS |
| 10 |
.nf |
| 11 |
.B void * |
| 12 |
.fi |
| 13 |
.SH DESCRIPTION |
| 14 |
A pointer to any object type may be converted to a pointer to |
| 15 |
.I void |
| 16 |
and back. |
| 17 |
POSIX further requires that any pointer, |
| 18 |
including pointers to functions, |
| 19 |
may be converted to a pointer to |
| 20 |
.I void |
| 21 |
and back. |
| 22 |
.P |
| 23 |
Conversions from and to any other pointer type are done implicitly, |
| 24 |
not requiring casts at all. |
| 25 |
Note that this feature prevents any kind of type checking: |
| 26 |
the programmer should be careful not to convert a |
| 27 |
.I void * |
| 28 |
value to a type incompatible to that of the underlying data, |
| 29 |
because that would result in undefined behavior. |
| 30 |
.P |
| 31 |
This type is useful in function parameters and return value |
| 32 |
to allow passing values of any type. |
| 33 |
The function will typically use some mechanism to know |
| 34 |
the real type of the data being passed via a pointer to |
| 35 |
.IR void . |
| 36 |
.P |
| 37 |
A value of this type can't be dereferenced, |
| 38 |
as it would give a value of type |
| 39 |
.IR void , |
| 40 |
which is not possible. |
| 41 |
Likewise, pointer arithmetic is not possible with this type. |
| 42 |
However, in GNU C, pointer arithmetic is allowed |
| 43 |
as an extension to the standard; |
| 44 |
this is done by treating the size of a |
| 45 |
.I void |
| 46 |
or of a function as 1. |
| 47 |
A consequence of this is that |
| 48 |
.I sizeof |
| 49 |
is also allowed on |
| 50 |
.I void |
| 51 |
and on function types, and returns 1. |
| 52 |
.SS Use with printf(3) and scanf(3) |
| 53 |
The conversion specifier for |
| 54 |
.I void * |
| 55 |
for the |
| 56 |
.BR printf (3) |
| 57 |
and the |
| 58 |
.BR scanf (3) |
| 59 |
families of functions is |
| 60 |
.BR p . |
| 61 |
.SH VERSIONS |
| 62 |
The POSIX requirement about compatibility between |
| 63 |
.I void * |
| 64 |
and function pointers was added in |
| 65 |
POSIX.1-2008 Technical Corrigendum 1 (2013). |
| 66 |
.SH STANDARDS |
| 67 |
C11, POSIX.1-2024. |
| 68 |
.SH HISTORY |
| 69 |
C89, |
| 70 |
POSIX.1-1990. |
| 71 |
.SH SEE ALSO |
| 72 |
.BR malloc (3), |
| 73 |
.BR memcmp (3), |
| 74 |
.BR memcpy (3), |
| 75 |
.BR memset (3), |
| 76 |
.BR intptr_t (3type) |