FreeBSD raspberry pi C compiler strangeness

Ian Lepore ian at freebsd.org
Wed Feb 26 19:58:59 UTC 2020


On Wed, 2020-02-26 at 20:45 +0100, Wojciech Puchar wrote:
> i wrote my program and tested completely my program on x64 laptop
> under 
> FreeBSD 11
> 
> then i compiled this program under FreeBSD on raspberry pi (quite
> latest 
> version downloaded less than 2 months ago).
> 
> And program didn't work properly.
> 
> Finally i found a problem.
> 
> char is signed by default on x64.
> 
> On raspberry pi char is unsigned by default.
> replacing "char" with "signed char" fixed problem completely.
> 
> Why char is unsigned on FreeBSD/raspberry pi?
> 

The C standard allows plain char types to be signed or unsigned by
default.  Char has always been unsigned by default on arm platforms
(not just freebsd, it's mandated by the ARM ABI document).

Usually when you run into trouble with this, it's a sign that your code
should be using int8_t, not char.  If the trouble arises with something
like calling getc(3) and testing for EOF, the problem is that getc()
returns an int, not a char, so you need to assign the return value to
an int for testing against EOF.

-- Ian



More information about the freebsd-hackers mailing list