Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2001:
[Freeciv-Dev] Re: Coding Guideline --- more variants
Home

[Freeciv-Dev] Re: Coding Guideline --- more variants

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Coding Guideline --- more variants
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 29 Nov 2001 17:42:01 +0100
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Thu, Nov 29, 2001 at 04:25:55PM +0100, Reinier Post wrote:
> > 11a: always braces
> >   switch(a) {
> >   case 2:
> >   {
> >     return 2;
> >   }
> >   case 3:
> >   {
> >     int x;
> >     ....
> >   }
> 
> This (11a) is my preference.

> BTW I seem to remember some C compilers or standards don't allow
> such intra-block variable declarations, while I much prefer them myself,
> I even create blocks to introduce them:

AFAIK this is allow by the standard. Nevertheless the code includes
such constructs and there no problem.

> int foo()
> {
>   int i;
> 
>   i=changing(i);
> 
>   {
>     int j;
> 
>     for (j=0; j<i; ++j) {
>       i=foo(j);
>     }
>   }
> 
>   return i;
> }
> 
> Has this been sorted out?  Have we voted on this?
> 
> QUESTION 11.5: declarations within blocks
> 
> /* A */  all declarations at start
> /* B */  declarations within block if possible
> /* C */  even create blocks to scope declarations where appropriate
> 
> My preference: C.

"Use the smallest possible scope". If interpreted in its purest way
this would mean C. However in the case above I wouldn't use C. This
depends on the size and the number of
variables. ai_military_findvictim defines 12 variables at the function
scope. This is too much. However the next function
ai_military_bodyguard uses 6 and this is ok for me.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "From what I am reading Win98 and NT5.0 will be getting rid of all that
  crap anyway. Seems that Microsoft has invented something called TCP/IP and
  another really revolutionary concept called DNS that eliminates the
  netbios crap too. All that arping from browsers is going to go away.
  I also hear rumors that they are on the verge of breakthrough discoveries
  called NFS, and LPD too. Given enough time and money, they might
  eventually invent Unix."
    -- George Bonser in linux-kernel


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