Debian Codegraph @

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

raw
1 .\" Copyright (c) 2022 by Alejandro Colomar <[email protected]>
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\"
6 .TH NULL 3const 2024-06-15 "Linux man-pages 6.9.1"
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-2008.
24 .SH HISTORY
25 C89, POSIX.1-2001.
26 .SH NOTES
27 The following headers also provide
28 .BR NULL :
29 .IR <locale.h> ,
30 .IR <stdio.h> ,
31 .IR <stdlib.h> ,
32 .IR <string.h> ,
33 .IR <time.h> ,
34 .IR <unistd.h> ,
35 and
36 .IR <wchar.h> .
37 .SH CAVEATS
38 It is undefined behavior to dereference a null pointer,
39 and that usually causes a segmentation fault in practice.
40 .P
41 It is also undefined behavior to perform pointer arithmetic on it.
42 .P
43 .I NULL \- NULL
44 is undefined behavior, according to ISO C, but is defined to be 0 in C++.
45 .P
46 To avoid confusing human readers of the code,
47 do not compare pointer variables to
48 .BR 0 ,
49 and do not assign
50 .B 0
51 to them.
52 Instead, always use
53 .BR NULL .
54 .P
55 .B NULL
56 shouldn't be confused with
57 .BR NUL ,
58 which is an
59 .BR ascii (7)
60 character,
61 represented in C as
62 .BR \[aq]\[rs]0\[aq] .
63 .SH BUGS
64 When it is necessary to set a pointer variable to a null pointer,
65 it is not enough to use
66 .BR memset (3)
67 to zero the pointer
68 (this is usually done when zeroing a struct that contains pointers),
69 since ISO C and POSIX don't guarantee that a bit pattern of all 0s
70 represent a null pointer.
71 See the EXAMPLES section in
72 .BR getaddrinfo (3)
73 for an example program that does this correctly.
74 .SH SEE ALSO
75 .BR void (3type)