Author: Robert Hyatt
Date: 21:55:48 07/04/03
Go up one level in this thread
On July 04, 2003 at 16:39:20, Gerd Isenberg wrote:
>On July 04, 2003 at 16:28:43, Jens Kahlenberg wrote:
>
>>On July 04, 2003 at 16:17:47, Gerd Isenberg wrote:
>>
>>>On July 04, 2003 at 13:56:09, Normand M. Blais wrote:
>>>>// This function runs fine (with or without optimization).
>>>>inline int s2i(const char *str)
>>>>{
>>>> // input: a square name (string) (ex: e4)
>>>> // output: a square number (integer) (ex: 36)
>>>>
>>>> int sq = (str[0] - 'a') + (8 * (8 - (str[1] - '0')));
>>>
>>>Another possible trap, if the coordinate string may be "empty".
>>>In this case "str" is the valid address of the terminator, but "str[1]" may
>>>already be outside a 4KByte page and an access violation occurs on some
>>>processors (x86 in regular protected mode).
>>>
>>>Gerd
>>
>>
>>And don't forget the real empty string:
>>ASSERT( str != 0 && *str != '\0' );
>>
>
>absolutely true - always check preconditions!
>
>I once had an strange "sporadic" error inside a c-like parser, where i was
>looking for relationale operators. To "simplify" program logic i "prefetched"
>ptr[i+1] before interpreting ptr[i] ;-)
That is known as a LR(1) parsing algorithm. Perfectly normal, but with a
potential "issue" if you aren't careful. :)
The first compiler I wrote as an undergrad used that parsing algorithm.
>
>>
>>>
>>>
>>>>
>>>> if (sq >= 0 && sq <= 63) return sq;
>>>>
>>>> return -1;
>>>>}
>>>>
>>>>
>>>>Why the first version of the function causes problem is not clear to me. Anyway.
>>>>I felt that it is fare for me to share this information taking into account that
>>>>I benefit greatly from others.
>>>>
>>>>Thank you,
>>>>
>>>>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.