[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Groff] Re: signedness problems
From: |
Thomas Klausner |
Subject: |
[Groff] Re: signedness problems |
Date: |
Thu, 3 Jul 2003 09:41:34 +0200 |
On Thu, Jul 03, 2003 at 09:12:29AM +0200, Werner LEMBERG wrote:
> Since `char' is always signed in groff, isn't there another
> possibility to fix this?
I believe the correct way is to just explicitly spell out
this assumption in the source code.
To quote from the gcc man page (-fsigned-char also exists):
`-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.
> I've thought of a configure test which sets
> the appropriate compiler flag. autoconf provides the macro
> AC_C_CHAR_UNSIGNED, defining __CHAR_UNSIGNED__; would the following do
> the right thing in src/include/lib.h (and some other places for code
> written in C instead of C++)?
>
> #ifdef __CHAR_UNSIGNED__
> typedef signed char char
> #endif
I added #define __CHAR_UNSIGNED__ to config.h and the paragraph above
(with an additional ';') to lib.h.
Compilation fails:
In file included from /usr/src/gnu/dist/groff/src/libs/libgroff/font.cpp:24:
/usr/src/gnu/dist/groff/src/include/lib.h:182: declaration does not declare
anything
Perhaps it would work with a define, but I think the right solution is
to just use 'signed' when one wants it...
Cheers,
Thomas