Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Update on VC++6.0 compiler problem

Author: Normand M. Blais

Date: 14:38:16 07/04/03

Go up one level in this thread


On July 04, 2003 at 14:44:46, Dieter Buerssner wrote:

>On July 04, 2003 at 14:26:42, Normand M. Blais wrote:
>
>>On July 04, 2003 at 14:11:02, Dieter Buerssner wrote:
>>
>>>On July 04, 2003 at 13:56:09, Normand M. Blais wrote:
>
>>>>	int sq = (*str - 'a') + (8 * (8 - (*(++str) - '0')));
>
>>I agree with you that he first version is problematic.
>
>Norman, it is not only problematic, it is just wrong (I hope, it does not sound
>offensive, it shouldn't)
>
>>But I was thinking that
>>pointer arithmetic would be fast.
>
>This is with today's hardware/compilers probably more often wrong than correct.
>Such advice may come from old PDP 11 days, where the compilers where not well
>optimizing, and which had pre and postincrement instructions.
>
>Some modern hardware may need to do some pointer arithmetric with this task, but
>for example x86 can perfectly fast fetch a value at an increment (especially
>when it is constant). Still pointer arithmetics sometimes will be faster. I
>suggest to use pointer arithmetics, when it fits more the algorithm (say for
>example to traverse a move stack), and indices when it fits more (say for a
>scalar product of 2 vectors).
>
>To make the behaviour defined:
>
>  int sq = *str - 'a'; /* For very pedantic people, this is not totally
>  portable, because ISO C does not guarantee, that all letters are contigious */
>  sq += 8 * (8 - (*++str - '0')); /* Numbers, however are always contigious */
>
>Most probably this will run not faster, and possibly slower than the more
>obvious, and easier to read second choice you made.
>
>BTW. *str and str[0] are exactly the same, as are *(str+1) and str[1].
>
>Regards,
>Dieter

Dieter,

I appreciate your comment. I knew I was opened to criticisms when I sent my post
but if I can learn in the process I don't mind. I'm not a programmer by
profession and I still have a lot to discover.

Normand



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.