When I call a function that expects a pointer, and I pass in a value, I get this warning, and I like that.
But when the value happens to be a literal ‘0’, I don’t get the warning. I think this is because C think it’s null-pointer, and not a value. Is there any way to still get warnings for 0-literals, because I already had some bugs because of it.
GCC supports a
nonnullattribute on function parameters that can do what you want (as long as the-Wnonnullwarning option is enabled):When compiled using
gcc -c -Wnonnull test.cI get:You can force this to be an error with
-Werror=nonnull.Note that this warning is only thrown when the null pointer literal (another name for
0) is used – the following code doesn’t trigger the warning: