[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] are signed chars signed :-) ?

From: David Brown
Subject: Re: [avr-gcc-list] are signed chars signed :-) ?
Date: Tue, 7 Sep 2004 09:08:04 +0200

> Bernard,
> > I just understood that 2 minutes ago by looking at the avr-libc source!
> > First time that I encounter such an environment! I have to go thru all
> > code to modify 'char' to 'signed char'.
> you probably know about the -fsigned-char commandline switch, don't

The "-fsigned-char" flag would definitely save him some effort, but it is
still best to be explicit in the code.  Writing code whose correctness
depends on compiler flags is a bad idea.

As a rule, plain "char" should only be used when you really mean a
character - i.e., a letter in a string.  "unsigned char" and "signed char"
are silly names - what sense is there in talking about a negative letter?
The best way (in that it makes your code more readable, and removes a source
of error) is to use typedefs to give sensible names to "unsigned char" and
"signed char", which you then use consistently.  A prime example would be to
simply include the <inttypes.h> from avr-libc, and use int8_t and uint8_t.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]