Article 6HWP4 CodeSOD: Clear This

CodeSOD: Clear This

by
Remy Porter
from The Daily WTF on (#6HWP4)

Andy found this simple function in a C project he's working on.

void clearVal(int x) { x = 0;}

This is a thing of beauty, right here. From the very first premise, the function is useless: set an integer to zero. It's not even clearer about its intent than the original one liner- arguably it's less clear.

But it also has the benefit of not doing anything. Whoever wrote this function perhaps intended it to take a pointer. But as written, this just creates a local variable called x, which starts with whatever value the caller passed in, and sets the value of the local variable to zero. Nothing outside the scope of this function gets changed.

otter-icon.png [Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments