Re: sprintf x signed values

David Brown <[email protected]> Sun, 27 Apr 2008 10:07:13 +0200
Newsgroups gmane.comp.hardware.motorola.microcontrollers.coldfire
Message-ID <[email protected]>
Ricardo Raupp wrote:
>  
> People
>  From Freescale forum I got a help wich explained my problem.
> Follow below the last chat ...
> Thanks everybody !!!
>  
> Daniel
>  
> You were rigth...my char was (some spirit did it..I don“t remember...) 
> defined as unsigned char by default.
> Follow attached the CW screeshoot where it was set...
> After I reset it...I got happy again ...
> Now it is working fine...
> Saturday nigth will ne good ....
> Thanks for your attention!!!!!!
> Ricardo Raupp
> 

Hi Ricardo,

It was good that you posted your again after you fixed your problem - 
many people forget to do that on mailing lists and newsgroups, but it 
makes the archives much more useful.  However, you haven't solved your 
problem - you've made it worse.

First though, a note on posting in mailing lists and other such 
discussion and help groups.  Attachments are rarely considered 
appropriate unless you have very good reason - and an attachment of a 
proprietary non-standard document format containing a screen-shot to 
show a single line of text is almost too absurd for words.  If you'd 
tried that one in a less friendly group, you'd be advised to give up 
embedded development, at least until you understand some basic use of a 
PC and email.

Back to your problem again.

Your problem is *not* that you picked an option for "signed" or 
"unsigned" for default char.  If you know whether your compiler uses 
signed or unsigned for char, you've misunderstood what "char" is and you 
are asking for trouble.

A plain "char" is for holding a character, such as part of a string. 
For stupid historical reasons, there are standard library functions in C 
that use "char" for byte data - these make far more sense as "unsigned 
char".  But for everything *you* write, use "signed char" or "unsigned 
char" as appropriate if you are storing 8-bit data.

So you want your "int8" to be a typedef of "signed char", not plain 
"char".  Better still, use the more modern "sint8_t" and "uint8_t" types 
that are standardised across compilers.
---
[email protected]              Send a post to the list.
[email protected]        Join the list.
[email protected]    Join the list in digest mode.
[email protected]     Leave the list.