Author: Jens Kahlenberg
Date: 13:28:43 07/04/03
Go up one level in this thread
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' );
>
>
>>
>> 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.