Liste des Groupes | Revenir à cl c |
On 7/6/24 7:49 AM, Thiago Adams wrote:I hope that defining NULL as nullptr will become common - but I would be surprised to ever see it being required by C standards.If you were creating C code today and could use a C23 compiler, would you use nullptr instead of NULL?The (small) problem with 0 or NULL being use is that in a context where you THINK you are passing a pointer, but the function actually is taking an integer value, 0 or NULL (defined as a 0) passes the syntax check.
>
I am asking because I think I will keep using NULL.
>
I like nullptr semantics but I don't like to introduce new element (nullptr) inside the code with no guarantee that the code will not mix both.
>
In the past we also didn't have a guarantee we are not mixing 0 or NULL.
>
I think the best scenario for a team guideline would be a style warning if 0 or nullptr is used and NULL to be defined as nullptr in a C23 compiler.
>
If C23 REQURIED NULL to be defined as nullptr, then NULL would have been used, but as far as I know, it is still allowed to be defined as 0 (unless you also have POSIX compatibility).
With POSIX Compatibility, where NULL must have the type of (void*) you also avoid the possible error, and thus the desire to use nullptr.
Les messages affichés proviennent d'usenet.