Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang's NULL definition in stddef.h clashes with msvc's crtdefs.h #12518

Closed
nico opened this issue Mar 1, 2012 · 6 comments
Closed

clang's NULL definition in stddef.h clashes with msvc's crtdefs.h #12518

nico opened this issue Mar 1, 2012 · 6 comments
Labels
bugzilla Issues migrated from bugzilla clang:headers Headers provided by Clang, e.g. for intrinsics

Comments

@nico
Copy link
Contributor

nico commented Mar 1, 2012

Bugzilla Link 12146
Resolution FIXED
Resolved on Sep 24, 2014 14:30
Version unspecified
OS All
Blocks llvm/llvm-bugzilla-archive#13707
CC @efriedma-quic

Extended Description

Compiling

#include <stddef.h>
#include <crtdefs.h>
int* a = NULL

without -nobuiltininc yields:

test.cc:5:16: error: expected expression
int* a = __null;

That's because clang's stddef.h defines NULL to __null, but crtdefs.h apparently defines __null to something else.

Not sure what the right fix is. Make __clang_null an alternate spelling of __null and define NULL to __clang_null in stddef.h?

@nico
Copy link
Contributor Author

nico commented Mar 1, 2012

Eli, since you said you'd rather not support -nobuiltininc -fsyntax-only: Do you have any opinion which direction to take in this bug?

@efriedma-quic
Copy link
Collaborator

How about just using "0" when -fms-compatibility is on? It's equivalent except that you'll get slightly worse warnings.

__clang_null is ugly, but making it an alias for __null is okay if necessary.

@nico
Copy link
Contributor Author

nico commented Apr 24, 2012

The reverse is an issue too: clang's stddef.h does "#undef __null". However, some ms analysis tool uses __null as an annotation and has a header that defines it to nothing in normal builds. With clang's current stddef, this code breaks:

#define __null // Emulate ms header
#include <stddef.h>

void f(__null void* p) {
}

@nico
Copy link
Contributor Author

nico commented Apr 24, 2012

r155490 fixes this by defining NULL to 0. Maybe I'll look into having a __clang_null another day.

@nico
Copy link
Contributor Author

nico commented Sep 24, 2014

__clang_null patch
Here's how __clang_null would look, it's very simple.

One side effect of this is that clang starts warning on many things where existing code passes NULL for some HANDLE and the HANDLE is an int behind the scenes – but even MSDN docs say to use NULL (e.g. http://msdn.microsoft.com/en-us/library/windows/desktop/aa363686(v=vs.85).aspx)

@tritao
Copy link
Mannequin

tritao mannequin commented Nov 26, 2021

mentioned in issue llvm/llvm-bugzilla-archive#13707

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:headers Headers provided by Clang, e.g. for intrinsics
Projects
None yet
Development

No branches or pull requests

2 participants