char is 8 bits. In this environment it also defaults to signed. I assume
that cTemp is an int. What you are seeing is sign extension. Try declaring
theChar as unsigned char.
Ed Deinstadt
-----Original Message-----
From: Michael McFarland <[EMAIL PROTECTED]>
To: 'Palm Development List' <[EMAIL PROTECTED]>
Date: Friday, July 09, 1999 11:43 AM
Subject: handling characters


>Greetings all,
>
>     I am getting started w/ Palm programming, and this is my first post.
> In working w/ serial communication I've stumbled on something that seems
>very strange to me.  Consider the following code:
>
>     #define MY_CHAR 0x80
>
>     my_fun()  {
>         char theChar;
>         char theString[10];
>         int theBoolean;
>
>         cTemp = 0x80;
>
>         theBoolean = (theChar == MY_CHAR);   // theBoolean is set to 0
>         StrPrintF(theString, "%x", cTemp);         // theString is set to
>"FFFFFF80",  which is 4294967168 or -128
>     }
>
>    From what I've seen so far, cTemp is being set to a 4-byte value with
>three 'FF' bytes preceding the byte I specified.  But the CW help files say
>a char is 8 bits, as I would expect on any system not using Unicode.  So
>what am I missing?
>
>    Michael McFarland
>
>

Reply via email to