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.