Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] Re: (PR#7195) inlining map_pos_to_index
Home

[Freeciv-Dev] Re: (PR#7195) inlining map_pos_to_index

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jshort@xxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#7195) inlining map_pos_to_index
From: "rwetmore@xxxxxxxxxxxx" <rwetmore@xxxxxxxxxxxx>
Date: Wed, 14 Jan 2004 10:32:58 -0800
Reply-to: rt@xxxxxxxxxxx

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


Jason Short wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=7195 >
> 
> rwetmore@xxxxxxxxxxxx wrote:
> 
>>Since macros will never be less efficient than inline functions, have no
>>compiler dependencies (since the preprocessor generates "C" code that is
>>handled by the compiler just like all other code), if one is interested
>>in performance optimization macros should always be used over inline
>>functions.
> 
> Just to remind you, in this case the macro form is less efficient than 
> the inline form.

Rubbish, Jason. Pure unadulterated rubbish :-).

I expect much better from you after our many learning exercises together.


If one were to follow your assertion to its logical conclusion, then we
should replace every line of "C" code with a  function call and inline
them because the inline optimizer is so much better than the fullblown
"C" optimizer.

Macros are not something the compiler ever sees. They are converted into
"C" code by the preprocessor. One can write any "C" code as a macro and
put any "C" code into a macro.


You may just have to gain a little more experience in "C" coding to
understand how to program "C" efficiently. That you haven't figured out
how is not an argument that macros are somehow less efficient, so please
don't generalize from your abilities.


If you go back and reread some of the past articles you may perhaps get
some ideas ... for example.

1)  Use local variables. Assiging globals to local variables at the start
     of a code block and then using only the local variables within the
     block lets the compiler know they are not subject to change except if
     done explicitly in the code block.

2)  Do not use globals, Globals are evil. Globals are only useful in Raimar
     code to subtly skew performance results by making apple/orange comparisons
     to support bogus coding practices. In general they lead to all kinds
     of difficult to track down bugs.

3)  But it you must ...
     Use "const" for such global environment parameters as map.xsize, and
     map.ysize. Override the const is the few special cases where they
     are initially set or updated with documentation on what conditions
     need to be followed to make the update (locally) safe.

With a little thought, I am sure you can come up with some "C" code that
is just as nifty as your inline effort. Once you do making a macro out of
it is not a big deal.

[...]
> jason

Cheers,
RossW
=====




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