On 2/8/23 14:23, Jeffrey Walton wrote:
NULL can be a literal 0 (nullptr cannot), so it
might be Ok to write:
if (*p != NULL || s.is_empty()) {
Although NULL is allowed to be a literal 0 , that's not required: NULL
can be nullptr or equivalent. Hence the above code is not portable to
C++11 or later.
For C++, code should prefer nullptr to NULL (assuming you're using the
Gnulib nullptr module), to catch porting mistakes like this. The same
would be true for C except that most GNU code is developed on glibc
where pre-C23 NULL is ((void *) 0) and so bugs like the above are caught
at compile-time anyway.