goody8 said:
Is there really? My, my! And here I am still using my PDP11 C
compiler these days.... Wow... I guess you really CAN learn
something new on usenet.
BTW - I have been programming professionally in C++ since 1990, in
Borland, MS and Mac. I've taught classes in C++. These days I'm
mostly using C#.
Impressive but so what?, I'm a professional programmer since 1969 (yes I'm
that old) in BCPL later in B followed by C in 1974 and since 1990 in C++
(with a few years of Assembly in between), I've built system level
components for (and at) DEC's PDP11, Ultrix, VAX VMS, Alpha Open VMS and
OSF later True UNIX 64 and Windows NT on Alpha, I wrote some of the HAL code
and drivers for NT Alpha was a developer on the Clusters for NT on alpha
(taken over by MSFT to build Windows Cluster Server) was member of the
porting group since the early beginning of NT (1990/1) [written for a large
part using C++, was completely rewritten in C ; you want to know why? - on
MIPS later on ALPHA system], until the port of Windows2000 for alpha (whe
even had a 64 bit version of W2K for Alpha never released you probably know
why). Still mostly using C/C++ as system language but also using C# for
general purpose.
What does this prove, guess nothing...
Nonsense. There is no real difference between C and C++ with regard
to the auto-incrementing.
*** Sure there is it's small but there is.
And either will work just fine, it's merely
a matter of personal preference. Even if I were to believe that there
is a difference between them (and I don't - see Helge Jensen's
comparisons in this thread of the machine language produce for each of
the cases, and others' benchmarks). But that's all compiler-dependent
anyway - some might very well be "slightly more efficient". But
unless you're doing it 10 million times in a tight loop, it's not
going to make any difference at all in your program.
*** Note: The machine language was produced by me, and is the result of
JITed C# code NOT C++, want to see what the C++ compiler generates? You
would be suprised.
And anyway, as I said, in my 30 years of professional programming, I
really don't recall anyone using pre-increment when post-increment
would also work. It just seems more natural to me to write i++ than
++i.
*** So does it to me, but as a said the new 'C++ design guides" do prefer
the pre-increment form ....
You don't have to believe me, look what experts have to say about this:
1. Herb Sutter.
Exceptional C++.
C++ In-Depth Series. Addison Wesley, 2000.
and
C++ Coding Standards
Page 50 Item 28. Prefer calling prefix forms.
2. Meyers' Effective C++ and More Effective C++
3.
http://givemefish.com/C++FAQ.pdf
1.4 What is the difference between++var and var++?
4.
http://www.artlogic.com/careers/styleguide.html
snip from :Large-scale Statements:
Note that we prefer to use the pre-increment ++i as a general habit. It is
guaranteed in all languages that use this construct to work identically to
the more commonly seen post-increment i++ that dates back to the earliest
days of the C language. In C++, however, maintaining this habit prevents
possible inefficiencies when looping over an object that exposes an
iteratable interface. Consider the likely cost difference between:
typedef std::vector MyVector;
MyVector vec;
// assume the vector gets filled here....
for (MyVector::const_iterator i = vec.begin(); i != vec.end(); i++)
{
// clever and important code here...
}
and:
for (MyVector::const_iterator i = vec.begin(); i != vec.end(); ++i)
{
// even more clever and important code here...
}
5.
http://www.robthebloke.org/cppdir/StandardTemplateLibrary.htm
6.
http://www.accu.org/bookreviews/public/reviews/d/d002169.htm
<snip
Unncessary use of post-increment:
It is now well known that for iteration pre-increment usually provides
better performance than post-increment. Still, the book uses post-increment
throughout all the examples, thereby creating and destroying an unnecessary
temporary. A good compiler may be able to optimise away that temporary,
still it is not good nor common practice. In fact, in other places avoiding
temporaries is explicitly a concern (Section 7.4.1, for example).
/snip>
And there's probably a lot more..
Willy.