This is what I consider fun

2011-10-10 18:21

Got a bug report. Studied the bug report. In it, apparently, a variable was ceasing to have its former value. Like, someone stored 3.0 in a variable, and a bit later, it was no longer equal to 3.0.

Mysterious? No. Not at all.

What’s mysterious is discovering that the variable is still equal to 3.0, but that the literal constant “3.0” in the source code isn’t anymore.

I now have a test program in which I can write printf("%f\n", 3.0); and get 0.000000.

That was a ton of fun, because it took me forever to figure out that I was looking at the wrong side of the problem.

Peter Seebach

---

Comment

  1. People really can write FORTRAN in any language…

    — Julian · 2011-10-11 01:11 · #

  2. Missing (float) cast in the absence of a correct prototype for printf()? Damn, I can never remember the promotion rules. Can’t reproduce, either.

    — DES · 2011-10-13 14:54 · #

  3. Nope!

    It was a kernel bug. The bug was that this would happen right after a fork(), but only at higher optimization levels.

    Problem was that the compiler had spotted the multiple references to “3.0” in the source code and moved it into a register which the kernel wasn’t preserving during a
    fork().

    Since the test was a test of whether values were surviving, it was pretty weird discovering that the values in memory were in fact surviving, but the test was failing. Took me a long time to realize that maybe the constant was the problem.

    seebs · 2011-10-13 15:26 · #

 
---