Date: Wed, 26 Feb 2020 12:58:51 -0700 From: Ian Lepore <ian@freebsd.org> To: Wojciech Puchar <wojtek@puchar.net>, freebsd-hackers@freebsd.org Subject: Re: FreeBSD raspberry pi C compiler strangeness Message-ID: <6eae8193e54b29320b63d4f1a3442a0c455fa12b.camel@freebsd.org> In-Reply-To: <alpine.BSF.2.20.2002262043150.32598@puchar.net> References: <alpine.BSF.2.20.2002262043150.32598@puchar.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6eae8193e54b29320b63d4f1a3442a0c455fa12b.camel>