Hi Maarten,
> I don't see why you assume BIT4 to be a signed char. I think it already is
> an int. But yes, after ~ it will certainly be an int.
I just guess that BIT4 is treated as signed char by looking into the
source code below,
---------- SDCC.lex ------------------
0[bB]{B}+{IS}? {
if (!options.std_sdcc)
{
yyerror ("binary (0b) constants are not allowed in ISO C");
}
count ();
yylval.val = constVal (yytext);
return CONSTANT;
}
--------------------------------------
----------- SDCCval.c ----------------
value *
constVal (const char *s)
{
/* snip */
/* let's start with a signed char */
SPEC_NOUN (val->type) = V_CHAR;
SPEC_USIGN (val->type) = 0;
errno = 0;
if (s[0] == '0')
{
if (s[1] == 'b' || s[1] == 'B')
llval = strtoull (s + 2, &p, 2);
else
llval = strtoull (s, &p, 0);
dval = (double)(unsigned long long int) llval;
is_integral = 1;
}
/* snip */
}
--------------------------------------
so maybe I was wrong. ;)
Anyway, the other question is how to avoid the casting. Currently I am
thinking of the following three ways:
1. explicit cast BIT4:
#define BIT4 (unsigned char)0x00100000
2. explicit cast ~BIT4:
P_IO_PortC_Data &= (unsigned char)~BIT4
3. turn on "-funsigned-char" option
but so far I only see #2 works. I guess #1 doesn't work is because
the integer promotions rule alway applies on ~ expression, even I cast BIT4
to unsigned char, BIT4 is always promoted to int by the rule.
As for #3, I am wondering when the "char" is considered unsigned by
default. Does the unsigness apply on user-defined variable only, or it
also affects how compiler treate constant (like 0bnn).
Thanks.
Regards,
chenwj
--
Wei-Ren Chen (陳韋任)
Homepage: http://people.cs.nctu.edu.tw/~chenwj
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user