Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > unsigned integer overflow behaviour

Reply
Thread Tools

unsigned integer overflow behaviour

 
 
bartek
Guest
Posts: n/a
 
      02-06-2004
Hello,

Please help me with the obvious...

Does the standard say anything about integer overflow? Does it result in
implementation defined behaviour?

Would the following code snippet result in '0' being displayed on all
implementations?

unsigned x(std::numeric_limits<unsigned>::max());
std::cout << ++x << std::endl;

Cheers,
b
 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      02-06-2004

"bartek" <(E-Mail Removed)2.pl> wrote in message news:Xns9487E4C48EE9Cbartekdqwertyuiopo2p@153.19.2 51.200...

>
> Would the following code snippet result in '0' being displayed on all
> implementations?
>
> unsigned x(std::numeric_limits<unsigned>::max());
> std::cout << ++x << std::endl;
>

Yes, It is required that unsigned variables roll over from their max value to zero.

3.9.1/4
Unsigned integers, declared unsigned, shall obey the laws of arithmetic modulo 2n where n is the number

of bits in the value representation of that particular size of integer.

 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      02-06-2004

"Ron Natalie" <(E-Mail Removed)> wrote in message news:4024078d$0$199$(E-Mail Removed). ..

> Yes, It is required that unsigned variables roll over from their max value to zero.
>
> 3.9.1/4
> Unsigned integers, declared unsigned, shall obey the laws of arithmetic modulo 2n where n is the number
>
> of bits in the value representation of that particular size of integer.
>

The thing after modulo is supposed to be 2 raised to the nth power. The superscript got lost in the
cut and pasting.

 
Reply With Quote
 
bartek
Guest
Posts: n/a
 
      02-06-2004
"Ron Natalie" <(E-Mail Removed)> wrote in
news:40240952$0$170$(E-Mail Removed):

(...)

> The thing after modulo is supposed to be 2 raised to the nth power.
> The superscript got lost in the cut and pasting.


Thank you. I did extrapolate that though.

Cheers,
b
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
Unsigned integer wrapping on overflow joe C++ 23 09-13-2010 10:35 PM
Re: Unsigned Integer Overflow on Multiplication and Division Keith Thompson C Programming 2 05-13-2010 08:48 PM
Re: Unsigned Integer Overflow on Multiplication and Division Eric Sosman C Programming 1 05-13-2010 08:18 PM
Unsigned integer overflow detection Raymond C++ 8 08-20-2007 06:44 PM



Advertisments