Changing The Value of Seven

1 PM March 4, 2004

Early versions of Fortran, I am told, allowed the programmer to redefine the value of seven by writing 7 = 8.1

We did something similar with C++, today, when we accidently redefined empty string (as in a literal ””) to be considerably less empty. It was surprising how much of our application didn’t break.

In the end, we traced the bug back to a call to the transform() STL function. When you call transform() on a string, you pass it a string::iterator telling it where to place the transformed characters. Unfortunately, string::iterator is a typedef for char *, so when you tell it to place the output into a new, empty string, guess what? The empty string literal gets clobbered.


1 Assuming you hadn’t messed up too many other literals, you could get it back again by writing 7 = 8 – 1.

By alang | # | Comments (1)
(Posted to Software Development)

Comments

At 16:49, 04 Mar 2004 Ian Bicking wrote:

There's a great obfuscated C program in there waiting to get out. Implementing a Turing Machine with reassigned literals? Rebuilding the integers inside the empty string? Using the integers you get that way with pointer arithmatic, to expand the set of integers?

(#)

Add Comment




(Not displayed)






(Leave blank line between paragraphs. URLs converted to links. HTML stripped. Indented source code will be formatted with <pre> tags.)




© 2003-2006 Alan Green