signedness of char on ARM vs x86

signedness of char on ARM vs x86

Andrew Daviel
Karma: 70
2008-04-06 04:40 UTC
I have been trying to compile the opencv library for my N810 using
scratchbox. My application is OK on x86 and compiles but doesn't work on
ARM, and I find
some of the library functions returning different results with supposedly
identical data. Going back over the library build I find some compiler
warnings such as
warning: comparison is always false due to limited range of data type
warning: converting of negative value `-0x00000000000000001' to `char'

After some time tracing back data include files and defines I find
that some modules in the library are doing arithmetic with char, and the
compiler spots e.g. static comparisons.

The following snippet shows the problem:

#include "stdio.h"
int main() {
int j = -2 ;
char k ;
unsigned char m ;
signed char n ;
m = j ; n = j ; k = j ;
if (j < 0) printf ("j < 0\n" ) ;
if (k < 0) printf ("k < 0\n" ) ;
if (m < 0) printf ("m < 0\n" ) ;
if (n < 0) printf ("n < 0\n" ) ;
}

On my i386 desktop, with gcc 4.0.2 or 3.2.3, k < 0
In scratchbox-ARMEL, with gcc 3.4.4, k > 0

By which I presume that "char" is signed on the 386 and unsigned on the
ARM.

Is there any way I can override the compiler default, or do I have to go
through everything by hand and see where char is used inappropriately ?

How general is this, that data types are different on different systems
(I know about the int/long issues on 64-bit machines ...) ?


--
Andrew Daviel, TRIUMF, Canada
Tel. +1 (604) 222-7376 (Pacific Time)
Network Security Manager
  •  Reply

Re: signedness of char on ARM vs x86

Juha Kuikka

2008-04-06 05:28 UTC
Char is indeed unsigned on ARM by default.

http://www.arm.linux.org.uk/docs/faqs/signedchar.php

You could try to give "-fsigned-char" to gcc when you build your library.

- Juha

On Sat, Apr 5, 2008 at 9:40 PM, Andrew Daviel <advax@triumf.ca> wrote:

>
> I have been trying to compile the opencv library for my N810 using
> scratchbox. My application is OK on x86 and compiles but doesn't work on
> ARM, and I find
> some of the library functions returning different results with supposedly
> identical data. Going back over the library build I find some compiler
> warnings such as
> warning: comparison is always false due to limited range of data type
> warning: converting of negative value `-0x00000000000000001' to `char'
>
> After some time tracing back data include files and defines I find
> that some modules in the library are doing arithmetic with char, and the
> compiler spots e.g. static comparisons.
>
> The following snippet shows the problem:
>
> #include "stdio.h"
> int main() {
> int j = -2 ;
> char k ;
> unsigned char m ;
> signed char n ;
> m = j ; n = j ; k = j ;
> if (j < 0) printf ("j < 0\n" ) ;
> if (k < 0) printf ("k < 0\n" ) ;
> if (m < 0) printf ("m < 0\n" ) ;
> if (n < 0) printf ("n < 0\n" ) ;
> }
>
> On my i386 desktop, with gcc 4.0.2 or 3.2.3, k < 0
> In scratchbox-ARMEL, with gcc 3.4.4, k > 0
>
> By which I presume that "char" is signed on the 386 and unsigned on the
> ARM.
>
> Is there any way I can override the compiler default, or do I have to go
> through everything by hand and see where char is used inappropriately ?
>
> How general is this, that data types are different on different systems
> (I know about the int/long issues on 64-bit machines ...) ?
>
>
> --
> Andrew Daviel, TRIUMF, Canada
> Tel. +1 (604) 222-7376 (Pacific Time)
> Network Security Manager
>



--
Madness takes it's toll. Please have exact change.
  •  Reply