A while ago I read on some C++ site that was fairly reputable that was basically said
prefix increment can be faster than postfix, but never slower, so you may as well use the prefix version if you don't care about the result. i.e. in a for() loop, ++i and i++ do the same thing.
Then a month or so later in my C++ class, my teacher (who was a grad student, not a professor yet) said the same thing basically.
Is this even true? Or is it just rule of thumb, or approximation? It might also depend on the compiler and platform. I would think it would be very hard to gauge a difference in speed with such a simple operation, but like it says, if it is at least as fast, wouldn't it be better to use? I guess the biggest problem is just the habit of people writing the postfix version more, such as in for loops.
I'm not too familiar with the inner workings of C or C++, but I have wondered if this can be considered true. I almost never see people use it though, so I'm inclined to believe that it is a myth?
prefix increment can be faster than postfix, but never slower, so you may as well use the prefix version if you don't care about the result. i.e. in a for() loop, ++i and i++ do the same thing.
Then a month or so later in my C++ class, my teacher (who was a grad student, not a professor yet) said the same thing basically.
Is this even true? Or is it just rule of thumb, or approximation? It might also depend on the compiler and platform. I would think it would be very hard to gauge a difference in speed with such a simple operation, but like it says, if it is at least as fast, wouldn't it be better to use? I guess the biggest problem is just the habit of people writing the postfix version more, such as in for loops.
I'm not too familiar with the inner workings of C or C++, but I have wondered if this can be considered true. I almost never see people use it though, so I'm inclined to believe that it is a myth?