-
Notifications
You must be signed in to change notification settings - Fork 18
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
Use nullptr
for all null pointer constants
#79
base: master
Are you sure you want to change the base?
Conversation
Be careful! Don't add this argument directly, add at least a macro that checks it and adds when compiler do really has it. Here is an example of macro: https://github.com/WohlSoft/AudioCodecs/blob/master/audio_codec_common.cmake#L17-L22 ac_add_cxx_warning_flag(zero-as-null-pointer-constant ZERO_AS_NULLPTR_CONSTANT) Anyway, please rename |
a8b0b32
to
ae366bc
Compare
Looks much better now! |
There seems to be misses? I get the following from my compiler:
P.S.: @Wohlstand: Can you apply the following to demo/CMakeLists.txt? demo/basics_multi.c seems to need it. diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt
index b4453f7..82991ce 100644
--- a/demo/CMakeLists.txt
+++ b/demo/CMakeLists.txt
@@ -6,4 +6,6 @@ include_directories(${CMAKE_SOURCE_DIR}/gme ${CMAKE_SOURCE_DIR})
link_directories(${CMAKE_BINARY_DIR}/gme)
+set (CMAKE_C_STANDARD 99)
+
add_executable(demo Wave_Writer.cpp basics.c)
|
@sezero Okay, I'm getting the same warnings as you now. I needed to build with clang. For some reason, GNU isn't picking up all of them. It seems to have something to do with how |
ae366bc
to
e6f519a
Compare
Well, the gcc I used is 4.9 which is pretty old. And I believe that the warning should actually be really about using actual To me, this patch is blah (sorry, I already don't like c++, much less using newer bloated standards of it.) |
I think there's an example that illustrates the problem pretty well: #include <iostream>
struct B {};
struct A
{
operator B*() {return 0;}
operator bool() {return true;}
};
int main()
{
A a;
B* pb = 0;
typedef void* null_ptr_t;
null_ptr_t null = 0;
std::cout << "(a == pb): " << (a == pb) << std::endl;
std::cout << "(a == 0): " << (a == 0) << std::endl; // no warning
std::cout << "(a == NULL): " << (a == NULL) << std::endl; // warns sometimes
std::cout << "(a == null): " << (a == null) << std::endl;
}
My understanding is that it looks at At some point, we start getting into the realm of ambiguity and it's probably better if we're just really explicit about our intentions with the code. @sezero I understand that some individuals may have reservations about adopting newer features and standards in programming languages, but the introduction of Consistently using |
Also add `-Wzero-as-null-pointer-constant` to cxx flags.
I think this can go in, yes? |
I want to merge this after nearest release. First that I should do is fixing the dual shared and static builds thing. |
Also added
-Wzero-as-null-pointer-constant
to cxx flags.Ensuring that only
nullptr
is used with pointer types can prevent accidental assignments or comparisons with non-pointer types, reduce the risk of subtle bugs, and improve code reliability. It also helps to avoid ambiguity and improve clarity and intent.