Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

function call in for loop condition

Name: Anonymous 2009-02-28 2:29

I got into an argument with a co-worker today about this snippet:


for (int i = 0; i < foo(); i++)
{
}


I told him that he shouldn't put the foo() function in the termination check of that for loop. He said that the compiler actually assigns the result of foo() to a variable and then sticks that in where foo() is at. I said that we can't rely on that. We're working in C++ on .NET. Who's right?

Name: Anonymous 2009-02-28 2:55

You are both wrong. It will not save foo() unless it is simple enough for the compiler to tell that it is pure. However, arguing over optimization here is pointless because a) you are initializing i inside the loop anyway, so I doubt the program is time critical, or even time neccesary to the extent where something like this would matter (or you are just immense faggots who shouldn't be trying to optimize anyway because you will do it in all the wrong places protip: run a speed diagnostic and find bottlenecks, don't jew around over insignificant shit. And then b) You are programming for .NET so speed is again, obviously a non-issue. The time cost associated with you both wasting time thinking about this was not worth it's own weight; and you are effectively costing your employer money. Go and do something productive.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List