Smooth Moves

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • adramolek@gmail.com

    Smooth Moves

    So I had this bit of strange looking code:

    if (led->m_to[i] != prev &&
    (FCanCrossSelf || !_hit[led->m_to[i]->m_index]));
    {
    cango.push_back (i);
    }

    I was having a problem where it was getting into the if statement even
    when the condition was supposed to be false. I could not, for the life
    of me, figure out what was going on. The condition has so many braces
    and arrows and things in it, and I had been staring at it for so long.
    Why was it getting into the if statement when the condition was false?
    I could print debugging info from inside the statement and verify it
    was false. I could step through in my debugger and watch it step into
    the statements, even when it evaluated to false. What was going on?

    Well it's obvious when I look at it now, but after *over* an hour of
    debugging, looking at conditions, looking at other code, checking for
    buffer overruns in strange places, I *finally* spotted the damn extra
    semicolon I accidentally typed at the end of the "if". See it? It's
    right there before that left curly brace.

    I slapped myself on the head pretty hard after realizing how dumb the
    mistake was. It's not the first time I've spent a long time debugging
    a simple syntax mistake like that.

    So now, I am taking a break for a few minutes, and I am wondering:
    what kinds of horror stories do people here have about silly mistakes
    like this one? Hours spent debugging when you typed a j instead of an
    i, or put a parenthesis in the wrong spot, an extra semicolon, a
    problematic #define. There's got to be some good stories out there!

    - AJ
  • Paavo Helde

    #2
    Re: Smooth Moves

    adramolek@gmail .com wrote in news:fa29c801-70d1-40b4-a965-cb8d79379426@
    59g2000hsb.goog legroups.com:
    So now, I am taking a break for a few minutes, and I am wondering:
    what kinds of horror stories do people here have about silly mistakes
    I think one of the best was when I accidentally entered íf instead of if.
    After getting some spurious errors I spent a lot of time checking the
    braces, the previous statements, semicolons etc. It never occured to me
    to look at the if word itself. However, finally I noticed that the syntax
    coloring had failed to color it...

    And just today I copy-pasted a little function from one file to another,
    and it stopped compiling, complaining that T is not a type name:

    /// Cast from signed integer pointer to unsigned integer pointer or back
    template<typena me T, typename U>
    T sign_cast(U p) {
    // .. some checks
    return reinterpret_cas t<T>(p);
    }

    Fortunately I have the habit to (nervously?) move around in the text by
    arrow keys when thinking, and I noticed that when going up or down in the
    text the "template" line is jumped over. It appeared that copy-pasting
    into text-mode emacs window somehow managed to screw up the linebreak
    before the "template" line - probably replaced by CR, so that everything
    looks OK on the screen, but the compiler thought template line was just a
    continuation of the comment...

    Regards
    Paavo

    Comment

    Working...