Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: a question about speed difference that I do not understand

Author: Dieter Buerssner

Date: 11:27:38 12/05/01

Go up one level in this thread


On December 05, 2001 at 14:16:40, Ed Schröder wrote:

>The book and your compiler might be in conflict. Usually "int" is seen as
>32-bits whereas "short int" is 16-bits. In most compilers this is the default
>setting. But you must find out yourself and test your compiler, it is crucial
>if speed is an issue, which is true for a chess program as 16-bit sucks.
>
>Also check your compilers default setting regarding the "sign". That is how
>the compiler will interprete the sign bit when you define variables. Example:
>
>char x=255;
>
>if (x < 0) { do something }      // option-1
> else { do something else }      // option-2
>
>Most compilers are set to interprete variable "x" as a signed value and thus
>will follow option-1. However if your compiler is set to "unsigned" as default
>then the instruction will take option-2.
>
>It is a common and mean trap in C++, the smallest mistake will cause all kind
>of crazy crashes or unpredictable strange results. Its most easy way to avoid
>this problem, just always include the sign status when you define a new variable
>or a new area.
>
>unsigned char x;
>signed int y;

This is only needed for chars, and of course very good advice for cases where
one uses chars as arithmetic types (instead of for charecter strings, where
using plain char will avoid many problems ...). signed int and int are allways
the same. The same goes for long and long long. char is the only exception for
the Standard types in C.

Regards,
Dieter




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.