Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Any reason to use C?

Author: Gerd Isenberg

Date: 11:00:37 07/29/03

Go up one level in this thread


On July 29, 2003 at 13:31:29, Dieter Buerssner wrote:

>On July 29, 2003 at 01:54:29, Gerd Isenberg wrote:
>
>>On July 28, 2003 at 19:00:41, Dieter Buerssner wrote:
>
>>i see your point - i have no problems with references, may be due to Java.
>>References are very intuitive for me, but i don't use them "randomly" in
>>functions.
>>Most often the "output" paramter by reference is the first (left) one - and i
>>use appropriate function identifiers, implying the desired side effect.
>>
>>  int bitScanAndReset(BitBoard &bb);
>>  void assignWithMask(int &target, int source, int mask);
>
>I would probably use
>
>  int assignWithMask(int source, int mask);
>
>which also has the advantage, that it can be used in nested function calls.

Hi Dieter,

i agree, but target is a "right" value too in the expression:

target = target ^ ((source^target) & mask);

therefore a third parameter is necessary

int assignWithMask(int target, int source, int mask);

But that is what Uri wan't to avoid, using target twice.

>
>>>It may even be a performance issue. I read your suggestion about the small
>>>inline functions vs. macros. I basically agree. But when using reference
>>>paramaters (your example did), things might be very different. This might make
>>>it very difficult or even impossible to make a good optimization for the
>>>compiler.
>>
>>I never found a problem so far. I guess from compilers point of view, there is
>>no pragmatical difference between a pointer and a reference.
>
>I remember at least one case, where the macro was faster, than a function call
>with a pointer parameter (actually, most probably the function had 2 outputs at
>least). I don't have the case handy, but looking over my macros, I might find it
>again. Perhaps the following rather constructed example can show the point:
>
>extern unsigned or_tbl[], and_tbl[]; /* non const */
>
>void foo(unsigned *ap, unsigned idx)
>{
>  /* Of course, one could write it in one line */
>  *ap &= and_tbl[idx];
>  *ap |= or_tbl[idx];
>}

Yes, that may happen, but i don't like macros soo much due to the known reasons.
My point was pointer versus reference rather than inlined versus macro ;-)

Cheers,
Gerd

<snip>



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.