gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gnugo-devel] I stepped on a bug


From: Dave Denholm
Subject: Re: [gnugo-devel] I stepped on a bug
Date: Thu, 06 Oct 2005 16:57:03 +0100
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.2 (usg-unix-v)

"Felix C. Stegerman" <address@hidden> writes:

> The problem seems to be signedness. I edited owl.c and changed char to
> signed char on lines 221, 4639, 4727, 4728 and 4863. Then I recompiled
> gnugo. After that a quick test seems to indicate the bug is gone.
> This fix is probable a bit to simple, and I haven't read the entire
> code (or even the entire file owl.c), but this should help you fix it.
>
> I'd appreciate it if you'd let me know whether this signedness problem
>  is a bug in gnugo or in gcc. I'm not sure whether chars are meant to
> be signed or unsigned by default
>

The c standard ducks this issue, and lets the c compiler choose
whether char is signed or unsigned. So without having looked at any
code, I'd assume it's gnugo's fault for making assumptions about the
sign of char.

gcc has an option :

`-Wchar-subscripts'
     Warn if an array subscript has type `char'.  This is a common cause
     of error, as programmers often forget that this type is signed on
     some machines.


c99 has stdint.h with "proper" sized types int8_t, uint8_t etc. These
are probably better for storing things which are small numbers rather
than ascii characters...

ah - elsewhere in gcc info there's


`-funsigned-char'
     Let the type `char' be unsigned, like `unsigned char'.

     Each kind of machine has a default for what `char' should be.  It
     is either like `unsigned char' by default or like `signed char' by
     default.

     Ideally, a portable program should always use `signed char' or
     `unsigned char' when it depends on the signedness of an object.
     But many programs have been written to use plain `char' and expect
     it to be signed, or expect it to be unsigned, depending on the
     machines they were written for.  This option, and its inverse, let
     you make such a program work with the opposite default.

     The type `char' is always a distinct type from each of `signed
     char' or `unsigned char', even though its behavior is always just
     like one of those two.

`-fsigned-char'
     Let the type `char' be signed, like `signed char'.

     Note that this is equivalent to `-fno-unsigned-char', which is the
     negative form of `-funsigned-char'.  Likewise, the option
     `-fno-signed-char' is equivalent to `-funsigned-char'.



dd
-- 
Dave Denholm              <address@hidden>       http://www.esmertec.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]