[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: error-verbose yycheck overrun
From: |
Tim Van Holder |
Subject: |
Re: error-verbose yycheck overrun |
Date: |
13 Mar 2003 14:32:31 +0100 |
On Thu, 2003-03-13 at 01:08, Paul Eggert wrote:
> > From: Akim Demaille
> > Date: Tue, 04 Mar 2003 08:22:39 +0100
>
> > I would nevertheless encourage ++i over i++ :(
> > Not for contradicting, but in order to augment as much as possible
> > the similarity between all the skeletons, and therefore use more C++
> > standards (where people pay more attention to the difference between
> > post- and pre-increment).
>
> But if i is a local integer variable, what is the difference between
> "i++;" and "++i;" in C++? In C, they're equivalent.
No they're not - but there probably isn't a single (real-world) compiler
that doesn't optimize away the difference if the returned value is
ignored.
++i -> { i += 1; return i; }
i++ -> { int __temp = i; i += 1; return __temp; }
> had thought they were the same in C++ too, but I'm no C++ expert.
No, like in C, post-increment needs to use a temporary - for ints this
isn't a big deal, and it's often optimized away by the compiler. For
objects this is a potentially much bigger deal (and since in such cases
the increment operators are user-defined, the compiler can't optimize
anything away). So "use pre-increment unless you absolutely need
post-increment's behaviour" is a very typical C++ coding convention.
Making distinctions here because it is an int is not a great idea -
consistency in coding style is a Good Thing(tm).
--
Tim Van Holder <address@hidden>