Computer Chess Club Archives


Search

Terms

Messages

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

Author: Sune Fischer

Date: 11:10:45 07/04/03

Go up one level in this thread


On July 04, 2003 at 13:56:09, Normand M. Blais wrote:

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

Can't it have something to do with the order of execution?
Isn't the compiler free to do *str both before and after ++str?

-S.

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