I am doing some functions in a program that is already started, and I see that it has in the header:
#include <stddef.h>
#include <stdio.h>
And I don't understand why include the library stddef.h
since according to what I searched in google what the library provides is the constant NULL
for the pointer type variables (among other things but that I don't use in the program).
When using pointers I often use NULL.
But it turns out that if I remove that inclusion the program works fine anyway. As if the bookstore stdio.h
already gave me the constant of the NULL
same.
What do you think it could be?
I can't show code and the one who gave me the program can't answer me.
Header
<stddef.h>
.According to the documentation that we can consult in cppreference, the header
Before C11 :<stddef.h>
provides the following:size_t
: type alias (typedef
) to an unsigned integral type . It is used as the return of the operatorsizeof
.ptrdiff_t
type alias (typedef
) to a signed integral type . It is used as the result of pointer arithmetic.NULL
a constant defined as a macro whose value is implementation dependent and is the value of a null pointer.offsetof
macro function that calculates the offset between the start of a structure and a member of that structure.max_align_t
type aliases (typedef
) on a type with alignment requirements as great as any other scalar type.alignas
syntactic sugar macro to keyword_Alignas
.alignof
syntactic sugar macro to keyword_Alignof
.noreturn
syntactic sugar macro to keyword_Noreturn
.Differences between c headers and c++ headers .
C++ adapts many of the C libraries to its own idiosyncrasies, classifying functions in namespaces or transforming some functions into templates, when a C library has been adapted to C++ its file receives one
c
as a prefix and the extension is removed. You should use the language-specific header, so if you're programming in C++ instead of using<stddef.h>
you should use<cstddef>
, read this thread to learn more about it.Headers may include other headers. Other headers you are using could include
<stddef.h>
and therefore you would be receivingNULL
. For example, if we look at GCC's implementation of<stdio.h>
, we see that one of the first things it does is actually include<stddef.h>
:The sttdef.h header defines several standard definitions (types and macros). Many of these definitions also appear in other headers, for example in stdio.h , and this is why you don't see changes to your code by not including sttdef.h . This header also defines (as indicated here ), in addition to the macro
NULL
, the variables:In the link that I left you, they define each variable and also show an example of the use of one of the macros (offsetof).
They may be looking for you to do a similar usage somewhere in your program, but if you say everything works, then there's no need to include the header.