Search code examples
cgcccompiler-warningscompiler-flags

gcc not warning when passing constant number to size_t * argument


My code is something like this:

#define ZERO_CONSTANT 0
foo(size_t * p_size);

foo(ZERO_CONSTANT); //Doesn't warn

Which gcc flag will make the call foo(ZERO_CONSTANT) to warn?


Solution

  • No compilation flag can possibly help you here. The C standard defines the literal 0 to stand in for the null pointer value of any type. Quite often you'll see 0, NULL and (void*)0.

    (Note well that this does not imply that the memory address is 0. Because it's undefined behaviour in general to assign an integral value to any pointer type, 0 is used as a placeholder literal for the null pointer).