On Sun, 2021-06-13 at 23:30 +0100, Jonny Grant wrote: > Hello > > This isn't real code, just an example to show. > > I've tried with: -Wall -Wextra -O2 and some other warnings, but > couldn't get this to generate a warning that *g was possibly de- > referenced. May I ask, does GCC have a way to get warnings when pointers > are not checked? > I had a look but -Wnull-dereference didn't help. > > #include <stdlib.h> > > #include <cstddef> > void f(int * g) > { > *g = 1; > > if(NULL == g) > { > exit(1); > } > } > > Best regards Jonny It was explained by Chris Lattner at http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html GCC (<= 4.4) had -Wunreachable-code which might work for this case. But it was too unreliable (as Chris said, generally there is no reliable way to do this) and removed in later releases. -- Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx> School of Aerospace Science and Technology, Xidian University