Liste des Groupes | Revenir à cl c |
On 02/04/2025 18:29, David Brown wrote:Fair enough - it is correct that there are some other standard headers that also define NULL (and/or a few other common identifiers such as size_t or wchar_t). The standard source of these common definitions, without pulling in a range of other identifiers, is <stddef.h>. (That is where it is documented in the standards.)On 02/04/2025 17:38, bart wrote:On 02/04/2025 16:26, Muttley@DastardlyHQ.org wrote:This program:>Never understood that in C++ never mind C. NULL has worked fine for 50 years.>
And it's been a hack for 50 years. Especially when it is just:
>
#define NULL 0
>
The common definition in C is :
>
#define NULL ((void*) 0)
>
Some compilers might have an extension, such as gcc's "__null", that are used instead to allow better static error checking.
>
(In C++, it is often defined to 0, because the rules for implicit conversions from void* are different in C++.)
>>>
You also need to include some header (which one?) in order to use it.
<stddef.h>, as pretty much any C programmer will know.
void* p = NULL;
reports that NULL is undefined, but that can be fixed by including any of stdio.h, stdlib.h or string.h. Those are the first three I tried; there may be others.
So it is not true that you need include stddef.h, nor obvious that that is where NULL is defined, if you are used to having it available indirectly.
Les messages affichés proviennent d'usenet.