> From: Mark Allums [mailto:m...@allums.com] >> int main() > { > const unsigned int n = -5; > cout << "The variable n is: " << n << endl; > return 0; > } > Results: > $ g++ -Wall -W prog.cpp -o prog > $ ./prog > The variable n is: 4294967291 > > > > This is expected behavior, but not defined by the standard because the > > > result is not portable. That is, a rollover value will occur,
Joe Pfeiffer : > I believe it is indeed defined behavior. > > 6.3.1.3 Signed and unsigned integers > > 1 When a value with integer type is converted to another integer type > other than _Bool, if > > the value can be represented by the new type, it is unchanged. > > 2 Otherwise, if the new type is unsigned, the value is converted by > > repeatedly adding or > > subtracting one more than the maximum value that can be represented > in the new type until the value is in the range of the new type.49) Me: > Yes, defined conversion, but not a defined *exact* result; that is, the > result is system dependent. > > So, yeah. I'm sorry, I meant, "so yes, you are correct." My first reply was vague, and might have sounded a bit unpleasant. This was not intended. -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/000901cde8d7$98e92000$cabb6000$@allums.com