conversion of short to unsigned it
Norman Diamond
ndiamond at watdaisy.UUCP
Sat Mar 23 04:08:34 AEST 1985
> unsinged int ui;
> unsigned short us;
> short s;
>
> s = -3;
> us = -3;
> ui = s;
>
> if ((unsigned int)s == us) printf("OOPS\n");
>
> prints OOPS meaning that fffffffd == 0000fffd !!!
It could mean 0000fffd == 0000fffd.
If (unsigned int) s is sometimes equivalent to (unsigned int) (int) s,
but other times equivalent to (unsigned int) (unsigned short) s,
then I don't think any rule is being violated. A compiler does not
have to be consistent in its treatment of ambiguous constructs.
(In fact, inconsistency should be encouraged because it quickens the
discovery of bugs.)
--
Norman Diamond
UUCP: {decvax|utzoo|ihnp4|allegra}!watmath!watdaisy!ndiamond
CSNET: ndiamond%watdaisy at waterloo.csnet
ARPA: ndiamond%watdaisy%waterloo.csnet at csnet-relay.arpa
"Opinions are those of the keyboard, and do not reflect on me or higher-ups."
More information about the Comp.lang.c
mailing list