null function pointers

I tried something like this:

void (*funcPtr)( void );
funcPtr = NULL;

void doStuff( void ) {
   doSomeOtherStuff();
}

if( funcPtr != NULL ) { //should not return true, since we have explicitly set funcPtr to NULL.  It does anyways :(
   funcPtr();   // will always run, whether or not funPtr as been initialized.  because it is uninitialized right now, random behavior occurs.
}

funcPtr = &doStuff();  //assign something and watch what happens next.

if( funcPtr != NULL ) {
   funcPtr();  // now calls doStuff() as we would expect.
}

syntactically, my example may not be strictly correct (I have not tested this exact code), but it ran incorrectly as in my example very recently when I tried this in a working sketch.

Am I overlooking something silly, or is this some sort of bug?

maybe it has something to do with how it's not possible to have a null function pointer, and thus the assignment was optimized away? I might be talking nonsense.

This compiles and works correctly:

void (*funcPtr)( void );

void doStuff( void ) {
  Serial.println ("the large goat");
}

void setup () 
{
  Serial.begin (115200);
  Serial.println ("begin");
  funcPtr = NULL;

  if( funcPtr != NULL ) {
    funcPtr();  
  }

  funcPtr = &doStuff;  //assign something and watch what happens next.

  if( funcPtr != NULL ) {
    funcPtr();  
  }

  Serial.println ("end");

}

void loop () {}

Output:

begin
the large goat
end

Your error is probably here:

funcPtr = &doStuff();  //assign something and watch what happens next.

That's calling doStuff, not assigning its address. You mean:

funcPtr = &doStuff;  //assign something and watch what happens next.