More fun with C. The following code _correctly_ prints "Not one". void isOne(int i) { if (i == 1) printf("One\n"); else printf("Not one\n"); } int main() { struct { int a:1; }s; s.a = 1; isOne(s.a); return 0; }
-
-
This is converting a constant that won't fit into the current datatype, not signed overflow. Unsigned to signed int conversion is impl-defined behavior.
-
Okay.. I see. If it's impl-defined then yes, that's the only correct behavior, because no matter what the impl-defined result is, int a:1 will never hold the value 1.
- Show replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.