[patch] Let stddef.h redefine NULL if __need_NULL is set

Nico Weber thakis at chromium.org
Sun Apr 27 19:59:42 PDT 2014


On Sun, Apr 27, 2014 at 5:13 PM, Nico Weber <thakis at chromium.org> wrote:
> On Sun, Apr 27, 2014 at 4:07 PM, Joerg Sonnenberger
> <joerg at britannica.bec.de> wrote:
>> On Sun, Apr 27, 2014 at 02:50:16PM -0700, Nico Weber wrote:
>>> small.cc:6:18: error: missing sentinel in function call [-Werror,-Wsentinel]
>>>   foo("bar", NULL);
>>
>> This is just broken code. Why we do we want to workaround that?
>
> Linux is kind of common, and there's no good way to work around this
> problem on an application code level that I can see.
>
> The Right Fix would be for the Linux code to not define NULL and use
> stddef.h (right?)

Thinking about this more, the kernel probably doesn't want to depend
on C headers (which would make some sense), which means the bug is
that some public glibc headers include linux kernel headers.

glibc seems to believe that __need_NULL is the thing to do is to use
this macro though:

  glibc thakis$ ack _need_NULL  | grep '\.h' | wc -l
        19

glibc historically wasn't very willing to change for clang, and we've
landed patches to work around it in the past. I agree the patch isn't
pretty; I'm happy for better suggestions, but I couldn't think of
anything better.

> – but since they do define NULL, they probably had a
> good reason for this at some point and probably won't change this
> soon. (Alternatively, they could define kNULL instead and use that
> instead of NULL everywhere, which too seems unlikely to happen soon.)
>
> Or is there something I'm missing?




More information about the cfe-commits mailing list