[cfe-users] Why is clang defining NULL as __null ??

David Blaikie via cfe-users cfe-users at lists.llvm.org
Mon Nov 4 09:27:45 PST 2019


clang generally also understands __null (for the same reasons GCC does - to
provide better diagnostics when using NULL in non-pointer contexts). See,
for example, this warning (not an error): https://godbolt.org/z/KvdW7a

Can't say I know much about the NDK or what version of clang it has, what
flags you might be passing, or why else it might be having trouble with
__null, unfortunately.

On Mon, Nov 4, 2019 at 9:15 AM pendyala syam via cfe-users <
cfe-users at lists.llvm.org> wrote:

> I have a .cpp file which has usage of *NULL* at several places. When I
> try to compile this cpp file for Android/x86 platform using clang++ on
> Windows machine + standalone tool chain, I am running into "expected
> expression" error at the places where *NULL* is used. I find the
> definition of *NULL* in stddef.h of clang headers provided by Android NDK
> as below.
>
> #if defined(__need_NULL)#undef NULL#ifdef __cplusplus#  if !defined(__MINGW32__) && !defined(_MSC_VER)#    define NULL __null#  else#    define NULL 0#  endif#else#  define NULL ((void*)0)#endif
>
> As far as I know, __null is specific to GNU compiler. In my case both
> _MSC_VER and __MINGW32__ are undefined because I am compiling for Android
> platform using clang++ and standalone tool chain. So it is hitting into define
> NULL __null. Since clang++ has no clue of what __null is, it is resulting
> into "expected expression" error.
>
> My question is, why is clang using macros(like __null) provided by GNU
> compiler? Or am I missing something here?
>
> Could somebody please help me understand. Thanks
> _______________________________________________
> cfe-users mailing list
> cfe-users at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20191104/2cae9ed2/attachment.html>


More information about the cfe-users mailing list