News for hackers. Stuff that matters.
Re:When you see a Heisenbug in C, change your compiler's opt... by greenyoda on Saturday March 01, 2014 @06:28PM (#7326687)
I've had a long career of writing C code that runs on many different operating systems and CPU architectures, and I don't think I've ever personally stumbled across a problem that was caused by a compiler bug. In my experience, heisenbugs (bugs that seem to disappear when you try to debug them)[1] are usually caused by bad memory references that corrupt different areas of memory - sometimes fatally, sometimes without visible effect - when the program is compiled in debug vs. release mode. For example, optimized code might put more variables in registers, thus changing the set of variables that are vulnerable to being clobbered by a buffer overflow.

Rushing to blame a bug in the compiler is, much more often than not, a way to waste a lot of time while debugging. Most commonly, we are the cause of our own bugs.

[1] https://en.wikipedia.org/wiki/Heisenbug

Re:When you see a Heisenbug in C, change your compiler's opt... by dalke on Saturday March 01, 2014 @11:06PM (#7327665)
While I'm fuzzy on the details now, one problem we had, back in the 1990s, was in C++ code which used comments with "\"s to make it look pretty.

   /// I am a comment! \\\
   a = 5;
The SGI OCC compiler accepted it just fine, as did most of the other compilers. I wasn't until we compiled on HP, or perhaps AIX, that we had a compiler which elided the "\" + newline to give

   /// I am a comment! \\a = 5;
and caused the downstream code to fail.

As for heisenbugs specifically, I agree with you. I just wanted to tell a story. :)

Re:When you see a Heisenbug in C, change your compiler's opt... by cnvogel on Sunday March 02, 2014 @04:46AM (#7328484)
I had a similar story I'd like to share. A colleague had written out the initialization data for some embedded component, and helpfully included the ASCII representation for some of the (mixed) binary/readable stuff we sent. So he wrote something along the lines of...

            unsigned char initdata[] = {
               0x01,  // some value, e.g. 513
               0x02,  // as 16bit, little endian
               0x40,  // ASCII @
               0x5c,  // ASCII \
               0x42,  // ASCII *
               0x09,  // number 9
              (...)
            };
Re:When you see a Heisenbug in C, change your compiler's opt... by mansr on Sunday March 02, 2014 @06:45AM (#7328779)
C99 explicitly does \-splicing of lines before comment processing:

  //\
  this is a comment

  /\
  / this is also a comment
GCC has an option (-Wcomment, enabled by -Wall) to warn about this and other likely mistakes involving comments (e.g. nested /* */ comments).
Re:When you see a Heisenbug in C, change your compiler's opt... by ja27 on Saturday March 01, 2014 @06:47PM (#7326794)
It's been a few years since I've really had one, but corrupting or using up the stack space was the cause of a couple of cases of seemingly weird behavior in C.