Debian Codegraph @

upstream/debian-unstable/man3/NULL.3const

raw
1 .\" Copyright, the authors of the Linux man-pages project
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\"
6 .TH NULL 3const 2026-01-05 "Linux man-pages 6.18"
7 .SH NAME
8 NULL \- null pointer constant
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <stddef.h>
15 .P
16 .B "#define NULL ((void *) 0)"
17 .fi
18 .SH DESCRIPTION
19 .B NULL
20 represents a null pointer constant,
21 that is, a pointer that does not point to anything.
22 .SH STANDARDS
23 C11, POSIX.1-2024.
24 .SH HISTORY
25 C89,
26 POSIX.1-1988.
27 .SH NOTES
28 The following headers also provide
29 .BR NULL :
30 .IR <locale.h> ,
31 .IR <stdio.h> ,
32 .IR <stdlib.h> ,
33 .IR <string.h> ,
34 .IR <time.h> ,
35 .IR <unistd.h> ,
36 and
37 .IR <wchar.h> .
38 .SH CAVEATS
39 It is undefined behavior to dereference a null pointer,
40 and that usually causes a segmentation fault in practice.
41 .P
42 It is also undefined behavior to perform pointer arithmetic on it.
43 .P
44 .I NULL \- NULL
45 is undefined behavior, according to ISO C, but is defined to be 0 in C++.
46 .P
47 To avoid confusing human readers of the code,
48 do not compare pointer variables to
49 .BR 0 ,
50 and do not assign
51 .B 0
52 to them.
53 Instead, always use
54 .BR NULL .
55 .P
56 .B NULL
57 shouldn't be confused with
58 .BR NUL ,
59 which is an
60 .BR ascii (7)
61 character,
62 represented in C as
63 .BR \[aq]\[rs]0\[aq] .
64 .SH BUGS
65 When it is necessary to set a pointer variable to a null pointer,
66 it is not enough to use
67 .BR memset (3)
68 to zero the pointer
69 (this is usually done when zeroing a struct that contains pointers),
70 since ISO C and POSIX don't guarantee that a bit pattern of all 0s
71 represent a null pointer.
72 See the EXAMPLES section in
73 .BR getaddrinfo (3)
74 for an example program that does this correctly.
75 .SH SEE ALSO
76 .BR void (3type)