“ What the f**k ? “, “ Are you kidding me? “, “ What !!! ”, “ That’s very stupid !” are the sort of sentences I often listen from programmers when I pass by them at my work place. Being a novice programmer, I am puzzled and a moment think of what these guys are reprimanding at. Just out of curiosity asked one of them- “ Whom do you guys usually reprove at while programming ? “. With eyes wide open he replied, “ Its the compiler “. His answer wasn’t satisfying enough to convince until I found myself in their shoes.
Mesh sub-division is the assignment task of my graphics course. Being a mac user, I program in Xcode, an IDE similar to Visual Studio(VS) on Windows. Everything was fine until I tested the code on VS-2008. The compiler complained a run-time error and was more than puzzled to find what healthy to Mac is sick on Windows.
void
MeshClass :: GetLastVertexID( void )
{
std::list<tVertex> :: iterator iter( m_verts.end() );
lastVertexID = (*iter)->id() ;
}
Trying to dereference the end() of any list/vector is definitely a run-time error and was puzzled to see a non-garbage value present in the variable lastVertexID when debugged on Xcode. Cleaning and rebuilding the project didn’t either help the Xcode’s compiler to recognize this run-time error. The VS-2008 compiler is intelligent enough in preventing me not to dereference the end of the list. However, later rectified the mistake by decrementing the iterator once before dereferencing -
void
MeshClass :: GetLastVertexID( void )
{
std::list<tVertex> :: iterator iter( m_verts.end() );
--iter ;
lastVertexID = (*iter)->id() ;
}
The instant VS-2008 compiler complained, I was out of all foul and filthy statements that I possibly could scold. I was reluctant enough even to see the run-time error message and rather spent time in praising Mac over Windows. After much midnight oil burnt in Mac-praising, found how possibly can a Mac compiler could safely run such unsafe code. The assignment not only learnt me lesson of how compilers are different from each other but also why programmers should have many compilers on friends-list to be successful.
Results :