Header <stddef.h>
.
According to the documentation that can be consulted in cppreference, the header <stddef.h>
provides the following:
Before C11 :
-
size_t
: aliases of type ( typedef
) to a integral type without sign. Used as operator return sizeof
.
-
ptrdiff_t
type alias ( typedef
) to a integral type with sign. It is used as a result of pointer arithmetic.
-
NULL
a constant defined as macro whose value is implementation dependent and is the value of a null pointer .
-
offsetof
function macro that calculates the offset between the start of a structure and a member of that structure.
After C11 additionally provides :
Differences between headers c and headers c ++ .
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 a c
as a prefix and it removes the extension. You should use the specific header of each language, so if you are programming in C ++ instead of using <stddef.h>
you should use <cstddef>
, read this thread to know more about this topic.
When using pointers I use NULL many times.
But it turns out that if I remove that inclusion the program works correctly anyway. As if the library stdio.h
already gave me the constant of NULL
likewise.
What do you think it can be?
Headers can include other headers. Other headers that you are using could include <stddef.h>
and therefore you would be receiving NULL
. For example, if we consult the GCC implementation of <stdio.h>
, we see that one of the first things you do is, effectively, include <stddef.h>
:
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ''AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#)stdio.h 5.3 (Berkeley) 3/15/86
*/
/*
* NB: to fit things in six character monocase externals, the
* stdio code uses the prefix '__s' for stdio objects, typically
* followed by a three-character attempt at a mnemonic.
*/
#ifndef _STDIO_H_
#ifdef __cplusplus
extern "C" {
#endif
#define _STDIO_H_
#define _FSTDIO /* ''function stdio'' */
#define __need_size_t
#include <stddef.h>