avr-gcc-list
[Top][All Lists]
Advanced

[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 13:20:06 +0200


> Yeah but when memory is rare you re-use the same variable for different
use
> in the same function. My 'char' was really a char until I needed to
perform
> some signed calculation later in the code.
>

Bad idea - use an optomising compiler (like gcc :-) instead of trying to
write code like that.  For local variables, gcc will keep the variable in a
register (where possible, and assuming you have optomisation turned on), and
it will happily re-use these same registers for other variables later in the
same function.


> -----Message d'origine-----
> De : address@hidden
> [mailto:address@hidden la part de David Brown
> Envoyé : mardi 7 septembre 2004 09:08
> À : address@hidden
> Objet : Re: [avr-gcc-list] are signed chars signed :-) ?
>
>
> > 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
> my
> > > code to modify 'char' to 'signed char'.
> >
> > you probably know about the -fsigned-char commandline switch, don't
> you?!?!?
> >
>
> 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.
>
>
>
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
>
>




reply via email to

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