Subject: Re: Kernel and compiler troubles
To: david@infotrek.demon.co.uk, RiscBSD mailing list <port-arm32@NetBSD.ORG>
From: Mark Brinicombe <amb@physig4.ph.kcl.ac.uk>
List: port-arm32
Date: 11/11/1996 18:59:21
>On a different note, I'm having trouble with one of the programs I use for
>my work. It appears to be related to the warnings I get at compile time.
>These warning do not appear when compiling for x86 Linux:
>
>run.c: In function `load_persona':
>run.c:679: warning: comparison is always 1 due to limited range of data type
>[cut]
>The next one is "comparison is always 0", and the line is:
>[cut]
Ok these are problems due the assumptions about the nature of characters.

on the arm characters are UNSIGNED (0 -> 255)
on i386 characters are SIGNED (-128 -> 127)

Lots of code (especially Linux code ? (given its roots)) will sometimes assume
things about characters and whether they are signed or not.

The basic problem is that the code you are compiling as not be written to
consider that chars on some architectures are different.

for example

char a;

a = -1;
if (a == -1) then
  printf("chars are signed\n");

will work on the i386
on the arm a will be assigned the value 255 and a comparison with a negative
number will fail.

Solutions:
Use integers rather than chars
explicitly declare variables as signed chars or unsigned chars as appropriate.

In your example temp must have been declared as a character. Without know the
code better I cannot say whether changing to ints is feasible. However
declaring
temp to be a signed char may help.

Cheers,
				Mark

-- 
Mark Brinicombe				amb@physig.ph.kcl.ac.uk
Research Associate			http://www.ph.kcl.ac.uk/~amb/
Department of Physics			tel: 0171 873 2894
King's College London			fax: 0171 873 2716