|
From: | Paul Eggert |
Subject: | Re: groff with "nullptr" and (without) gnulib module causes error |
Date: | Wed, 8 Feb 2023 17:46:42 -0800 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 |
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.
[Prev in Thread] | Current Thread | [Next in Thread] |