Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2004:
[Freeciv-Dev] Re: (PR#2521) general effects framework
Home

[Freeciv-Dev] Re: (PR#2521) general effects framework

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: kaufman@xxxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2521) general effects framework
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 15 Mar 2004 08:53:08 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=2521 >

rwetmore@xxxxxxxxxxxx wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=2521 >
> 
> 
> Huh?
> 
> If the macro codes a replacement variable pcity, that would cause a
> lot of problems if someone accidently dropped a variable declaration
> or other scoping tweak that normally overrode it or the like.
> 
> It also leads to confusion when trying to actually use a local variable
> in iterator like context, i.e. not self-contained macro but one with
> several parts. Making this have the same style is just better coding
> so no one needs to think twice about what is local the macro and what
> is not depending on whether the macro is currently self-contained or not.
> 
> The rule ... Anything used totally within the macro context should use
> internal not external naming conventions. Anything with an underbar is
> *not* then legally visible/usable by the programmer outside of the macro.

This doesn't apply to the macro's variables.  For instance the following 
works exactly like it should

   #define iterate(i) { \
     int i; \
     for (i = 0; i < 10; i++) {

   void main()
   {
     int i = 100;

     iterate(j) {
       printf("%d\n", i + j);
     } } }
   }

Adding underscores to these parameters isn't useful at all and conforms 
to no current standard (a lot of iterators do use weird naming for their 
arguments, but there is no *standard*).

For variables used entirely inside the macro, you are right.  The 
following does not work properly (and in fact won't even compile).  The 
macro should use value _j rather than j.  The difference is that this 
value is not a macro argument and is therefore used exactly the way it's 
written in the macro.

   #define iterate(i) \
     { \
       int i, j; \
       for (j = 0; j < 10; j++) \
         for (i = 0; i < j; i++) {

   void main()
   {
     int i = 100;

     iterate(j) {
       printf("%d\n", j);
     } } }
   }

jason




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