X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCval.c;fp=src%2FSDCCval.c;h=de08d2a6cdb632183032f34cdc0cb97606e4e735;hb=e8f8c8a5a143a088419bcd33fe3591c54f3fb128;hp=649388f7f6e0c442cf0d15949e880495fe81a883;hpb=41dcb1719a48d2e6b08a12d089391c769fc781f3;p=fw%2Fsdcc diff --git a/src/SDCCval.c b/src/SDCCval.c index 649388f7..de08d2a6 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -698,9 +698,9 @@ constFixed16x16Val (const char *s) value *constVal (const char *s) { value *val; - bool hex = FALSE, octal = FALSE; char *p; double dval; + bool is_integral = 0; val = newValue (); /* alloc space for value */ @@ -710,27 +710,22 @@ value *constVal (const char *s) SPEC_NOUN (val->type) = V_CHAR; SPEC_USIGN (val->type) = 0; - if (s[0] == '0') - { - if (s[1] == 'x' || s[1] == 'X') - hex = TRUE; - else if (isdigit(s[1])) - octal = TRUE; - } - errno = 0; - if (hex || octal) + if (s[0] == '0') { - dval = strtoul (s, &p, 0); - if (errno) - { - dval = 4294967295.0; - werror (W_INVALID_INT_CONST, s, dval); - } + if (s[1] == 'b' || s[1] == 'B') + dval = strtoul (s + 2, &p, 2); + else + dval = strtoul (s, &p, 0); + is_integral = 1; } else + dval = strtod (s, &p); + + if (errno) { - dval = strtod(s, &p); + dval = 4294967295.0; + werror (W_INVALID_INT_CONST, s, dval); } /* Setup the flags first */ @@ -779,7 +774,7 @@ value *constVal (const char *s) } else if (dval > 0x7fff && !SPEC_USIGN (val->type)) { /* check if we have to promote to long int */ - if ((hex || octal) && /* hex or octal constants may be stored in unsigned type */ + if (is_integral && /* integral (hex, octal and binary) constants may be stored in unsigned type */ dval <= 0xffff) { SPEC_USIGN (val->type) = 1;