7

PEMDAS... or just hit the programmer with a large stick

 3 years ago
source link: http://rachelbythebay.com/w/2012/09/01/code/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
PEMDAS... or just hit the programmer with a large stick

Writing

Software, technology, sysadmin war stories, and more.

Saturday, September 1, 2012

PEMDAS... or just hit the programmer with a large stick

How well do you know your C++ operator precedence rules?

int count = 0;
if (it != purple_monkey_dishwasher_.end()) {
  for (int i = 0; i < (it->second).size(); ++i) {
    if (SYSTIME->Now() - (it->second)[i] < kOneDay) {
      ++count;
    }
  }
}

SYSTIME->Now() is a double. kOneDay is an int with a (non-leap-second) day's worth of seconds.

purple_monkey_dishwasher_ has been renamed to protect the guilty.

I had to stare at that one for a while to make sure I understood it.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK