Log in

No account? Create an account

Previous Entry | Next Entry

The Department of Redundancy Department

At work today, I was asked to patch some code on a project that I haven't worked on for years, and even then I only worked on the TCL side. The fix for today required me to delve into the C++ side of the code, though, to properly pass some data around. While working on this unfamiliar code, I ran across this stunning little snippet: (paraphrased)

const_cast<char *>(string("true").c_str());



For those not familiar with C++, you can write that same line exactly as:


Writing it the first way is like taking a glass of water, putting it in the freezer, then thawing it in the microwave to get a glass of water.

Obviously the last person to work on this code wasn't very C++ savvy, to say the least.

This isn't even covering the fact that it's kind of dodgy to cast a read-only string as writable, but at least there are semi-valid reasons to do that.


( 1 comment — Leave a comment )
Apr. 3rd, 2007 05:31 am (UTC)
A properly compiled bit of code would put the string in a write-only page so any attempt to write to it would cause a crash. It would be a fun one to watch someone try and track down until they check what that address it crashed on is actually pointing to.

And the first bit, I knew what it did, but your water analogy was rather amusing.
( 1 comment — Leave a comment )

Latest Month

February 2018


  • 17 Oct 2011, 19:18
    Clever! ^_^
  • 7 Oct 2011, 08:38
    Was each link made from two pieces, or was there fill material inside that you removed? I'm having trouble seeing how to print these in a makerbot-compatible way (though I could just be overlooking…
  • 5 Oct 2011, 22:40
    Nah. It'd just take a dissolvable support material and higher resolution. There are commercial 3d printers out there that can print ball bearing assemblies in one pass, fully assembled.
  • 5 Oct 2011, 18:46
    Nice! ^_^ I was going to be flabbergasted if you were actually able to print it as a unit, but I guess that would take antigravity.
  • 5 Oct 2011, 18:19
    I printed each piece individually and assembled them after some cleanup. I did print four segments at a time, though, unattached, in a 2x2 grid.
Powered by LiveJournal.com
Designed by Lilia Ahner