I had a flawed function like this:
The problem is that the value of c is not defined the 2nd time the function is called (and subsequently). It somehow worked fine under CygWin compiled with gcc. So I didn't spot the flaw until it ran incorrectly under Windows complied with VC++ 2010. Then I found the error and changed the code to something likeCode:fn(){ char c; if (runFirstTime){ #ifdef VC c='\\'; #else c='/'; #endif } ... // c is used in the rest of the function to construct some pathnames }
So now it works correctly under Windows. Then I re-compiled the new code with gcc and to my surprise gcc produced exactly the same binary!Code:fn(){ #ifdef VC const char c='\\'; #else const char c='/'; #endif ... }How can this be? Does the gcc compiler see my flaw and fix it for me somehow? If so I am truly amazed.




How can this be? Does the gcc compiler see my flaw and fix it for me somehow? If so I am truly amazed.
Reply With Quote