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

Pages: 1-

i++ or ++i

Name: Anonymous 2011-09-11 21:20

I notice in for loops that the more experienced programmers will increment with ++i while the beginners use i++.

Is there every a reason to use one over the other or does it just give you a sense of superiority?

Name: Anonymous 2011-09-11 21:23

++i is faster in a certain retarded C-derived language.

Name: Anonymous 2011-09-11 21:35

>>2
++i is on very rare occasions faster in a certain retarded C-derived language.
FTFY.

Name: newfriend 2011-09-11 22:29

Is that retarded C-derived language named Jave?

Name: Anonymous 2011-09-11 22:31

>>2
Those are known as non-conforming implmentations you idiot. Of course the only way you would have known something like this is if you would have read one of the ANSI/ISO C standards instead googling shit.

Name: Anonymous 2011-09-11 22:31

i += 1 is the only way.

Name: Anonymous 2011-09-11 22:52

++i; is faster than i++; if your compiler is retarded.

Name: Anonymous 2011-09-11 22:53

>>6
i = i + 1 is the master race.

Name: Anonymous 2011-09-12 0:18

The compiler, regardless of whether it's C or C++, will optimize post-decrementation (i++) to pre-decrementation (++i) if the return value is not used IFF the type of i is integral (for example an int or a non-void pointer).

However, C++ iterators are often not integral or pointer types. They have their own over-ridden operator++ functions. If those operators are not inline functions, or if inlining is disabled in the case of debug-builds, the compiler can't make the above optimization. In which case, pre-increment on iterator variables is always faster because no temporary is created. This is why the experts, when programming in C++, choose to use pre-increment.

Using it here or there might seem as premature optimization, but it's one of those things that have no associated cost to the programmer to do, and when done consistently throughout your code-base can help make a small difference, especially in debug builds (nothing worse than trying to debug a program that is extremely fucking slow in debug mode).

Name: Anonymous 2011-09-12 0:30

>>5
back to /g/, please

Name: Anonymous 2011-09-12 1:05

>>10
You could've just called him a retard, you know.

Name: Anonymous 2011-09-12 2:06

>>9

thank you

Name: Anonymous 2011-09-12 5:46

in C ++i; is ``equivalent'' to i++;. in C++, however, it's not.

Name: Anonymous 2011-09-12 7:43

>>13
are you kidding me?

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