Computer Chess Club Archives


Search

Terms

Messages

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

Author: Leen Ammeraal

Date: 22:13:20 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')));
>


You made a serious error: you took it for granted that
++str would be executed after the evaluation of
the term (*str - 'a'). However, the order of evaluation
of terms in an expression is undefined. This is an
official C++ rule and has nothing to do with VC++6.
Apparently VC++6's behavior in this regard is
different in debug and release mode, but the compiler
is entitled to do so.
Just replace (++str) with (str + 1) and everything should work
fine!
Best wishes,

Leen Ammeraal



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.