Meaning and Definition of NULL

Need help with C, C++, perl, python, etc?

Meaning and Definition of NULL

Postby bentHnau » 2018-12-29 04:41

When I look in stddef.h. I see that NULL has multiple definitions:

Code: Select all
403 #define NULL __null
404 #else   /* G++ */
405 #ifndef __cplusplus
406 #define NULL ((void *)0)
407 #else   /* C++ */
408 #define NULL 0

How is the appropriate definition for a given context chosen? And what exactly does ((void *) 0) mean? My book says that it is simply an address, but what does the 0 represent?
Debian Stretch x64 on a Dell XPS 17 laptop
Posts: 124
Joined: 2014-01-07 01:43
Location: California

Re: Meaning and Definition of NULL

Postby peter_irich » 2018-12-29 12:55

I think it is simply data type (void *). There are values of the different types: int, double, float and others
and pointers to this types, its differs by length and format, so there is and type (void *).
"0" means the this pointer does not dereference.

Posts: 1239
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation

Return to Programming

Who is online

Users browsing this forum: No registered users and 6 guests