Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2001:
[Freeciv-Dev] Re: [patch] const-int-ize SETTINGS_NUM
Home

[Freeciv-Dev] Re: [patch] const-int-ize SETTINGS_NUM

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Justin Moore <justin@xxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [patch] const-int-ize SETTINGS_NUM
From: Trent Piepho <xyzzy@xxxxxxxxxxxxx>
Date: Wed, 15 Aug 2001 10:58:38 -0700 (PDT)

On Wed, 15 Aug 2001, Justin Moore wrote:
> 
> Just a minor nitpicky patch ...
> 
> Rather than macro-ize SETTINGS_NUM in stdinhand.c and have it recalculate
> the size every time you reference it, why not make it an int or const int

Everything in that macro is a compile time constant, even the worst compiler
will optimize that into a single constant number.  You've replaced a constant
number with a variable, not an improvement.

For instance, you could do something like:

int some_array[SETTINGS_NUM];  /* One entry for each setting */

when it's a macro, but when it's a variable that won't work.  Also, this code,
#define NUM_X (sizeof(X)/sizeof(X[0])), is a common construct in C
programming.  I've probably written that hundreds of times and I see it all
over the place.  I've never seen anyone want to assign it to a global
variable.

Though I do see something I would change here.  This code in stdinhand.c has a
few constants called XXXX_NUM, like SETTINGS_NUM, CMD_NUM, etc.  I would
normally call these constants NUM_XXXX or maybe MAX_XXXX or MAX_NUM_XXXX.  And
it would seem, so would most other programmers.  Searching all of freeciv, I
can't find one instance of XXXX_NUM outside of the code in stdinhand.  I do
many many constants with names like NUM_XXXX or MAX_NUM_XXXX however.  But I
don't like to gratuitously rename variables in code that's already written, so
I'm not going to make a patch for it.



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