Computer Chess Club Archives


Search

Terms

Messages

Subject: Update on VC++6.0 compiler problem

Author: Normand M. Blais

Date: 10:56:09 07/04/03


Hi,

First, I would like to thanks everybody for their help. No one can succeed
alone.

The problem that I had was that my program would not run properly when compile
with optimization for speed but would run ok in debug version or in release
version with default optimization. I found that the problem was with a specific
function and the way it was coded:

// This fuction runs with no problem in debug version or release version with
// default optimization.
// But it fails in release version with optimization for speed.
inline int s2i(const char *str)
{
	// input:  a square name   (string)  (ex: e4)
	// output: a square number (integer) (ex: 36)

	int sq = (*str - 'a') + (8 * (8 - (*(++str) - '0')));

	if (sq >= 0 && sq <= 63) return sq;

	return -1;
}


// 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')));

	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.01 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.