This is apparently a regression in gcc 5.2.0 - and, as far as I can tell, weird.
With gcc 4.4.5 and 4.8.4, the program (after adding the required #include <stddef.h> ) issues warnings in both return NULL; , even without additional command line options.
With gcc 5.2.0, warnings are not issued even with gcc -c -Wall -Wextra -std=c99 -pedantic . For the second, returning the value from the void function, diagnostics is required.
Now here is the weird part.
$ gcc --version | head -n 1 gcc (GCC) 5.2.0 $ cat cc #include <stddef.h> int function(void) { #ifdef USE_NULL return NULL; #else return ((void*)0); #endif } void procedure(void) { #ifdef USE_NULL return NULL; #else return ((void*)0); #endif } $ gcc -c cc cc: In function 'function': cc:7:12: warning: return makes integer from pointer without a cast [-Wint-conversion] return ((void*)0); ^ cc: In function 'procedure': cc:15:12: warning: 'return' with a value, in function returning void return ((void*)0); ^ $ gcc -c -DUSE_NULL cc $
When USE_NULL defined, no warnings are generated. Compiling with gcc -E -DUSE_NULL (which outputs the preprocessor output to stdout) confirms that NULL is defined as ((void*)0) . But when I replace NULL with ((void*)0) , warnings are generated (as it should be).
I do not know what's happening. Once the NULL macro has been expanded, it must be indistinguishable from ((void*)0) , and yet the behavior of the compiler changes depending on which one is used.
source share