This is what I consider fun


Categories: GeekStuff

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.

Comments [archived]

From: Julian
Date: 2011-10-11 02:11:06 -0500

People really can write FORTRAN in any language…

From: DES
Date: 2011-10-13 15:54:11 -0500

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

From: seebs
Date: 2011-10-13 16:26:07 -0500


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

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.