Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] Re: (PR#2745) Change style guide to favor a++ instead of +
Home

[Freeciv-Dev] Re: (PR#2745) Change style guide to favor a++ instead of +

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2745) Change style guide to favor a++ instead of ++a
From: "rwetmore@xxxxxxxxxxxx via RT" <rt@xxxxxxxxxxxxxx>
Date: Tue, 7 Jan 2003 21:16:06 -0800
Reply-to: rt@xxxxxxxxxxxxxx

If you don't immediately use the value a++ is good.

If you do, then the compiler has to save a somewhere
before doing the update, and tends to generate extra
instructions. 

In the latter case ++a is better as it can just update.

So either
  for( i = 1; i < max; i++)
or
  for( i = 0; ++i < max; )

with the sedond actually generating more efficient code.

Cheers,
RossW
=====

At 03:32 AM 03/01/07 -0800, Raimar Falke via RT wrote:
>
>
>$ grep -Irn '[a-nA-Z][+][+]' .|fgrep .c|wc -l
>   1961
>$ grep -Irn '[+][+][a-nA-Z]' .|fgrep .c|wc -l
>    132
>
>From these 132 cases some are in intl/ (out of reach), some are
>required:
>  ./client/gui-sdl/gui_dither.c:516:      if (++h >= NORMAL_TILE_HEIGHT /
2) {
>  ./server/mapgen.c:1888:  && ++j < 500) {
>but the larger part doesn't require it. for loops like
>  ./client/gui-sdl/optiondlg.c:347:  for (i = 0; pModes[i]; ++i) {
>can be replaced. And simple statements like:
>  ./client/gui-mui/messagedlg.c:111:          ++err;
>  ./common/rand.c:208:      ++behaviourchange;
>  ./server/unithand.c:187:            ++number_of_upgraded_units;
>also doesn't need it.
>
>       Raimar
>
>-- 
> email: rf13@xxxxxxxxxxxxxxxxx
>  The trick is to keep breathing.






[Prev in Thread] Current Thread [Next in Thread]