Overly Aggressive Optimization?
SRLM
Posts: 5,045
Hi All, I have a curious problem. I have the following code:
When I run this program it does not work. When I change the first function to
the function works. But shouldn't the call in the conditional always be evaluated? ListFiles() can be called at any time (it's serial port controlled), so I don't see how the compiler can evaluate and reduce the function.
I'm running in -Os -mcmm. Curiously, the first function works when I enable via #define my debug serial port (which is not used in any of the functions here).
Anyway, does anybody have any hints or ideas?
void ListFiles(const char * const parameter) { if (dc.ListFiles() == false) { //BluetoothError("SD not available."); } }
bool ListFiles(void) { bool successFlag = false; ... if (DiskReady() == true) { ... successFlag = true; } return successFlag; }
When I run this program it does not work. When I change the first function to
void ListFiles(const char * const parameter) { dc.ListFiles(); //if (dc.ListFiles() == false) { //BluetoothError("SD not available."); //} }
the function works. But shouldn't the call in the conditional always be evaluated? ListFiles() can be called at any time (it's serial port controlled), so I don't see how the compiler can evaluate and reduce the function.
I'm running in -Os -mcmm. Curiously, the first function works when I enable via #define my debug serial port (which is not used in any of the functions here).
Anyway, does anybody have any hints or ideas?
Comments
Are you sure that dc.ListFiles() is declared properly in the scope of the first ListFiles? Could there be some kind of polymorphism issue?
I forgot all about the assembly output. I've just had to get something working for the near term. I'll be able to dive more into this later in the week. I'll let you know what I find.
No polymorphism here, though. The first ListFiles() is a function above main, the second ListFiles() is in an class. Besides the coincidence of sharing a name they don't have anything in common.
-Phil