Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Negative values in unsigned int

Reply
Thread Tools

Negative values in unsigned int

 
 
Urs Thuermann
Guest
Posts: n/a
 
      09-08-2008
I wasn't able to find an answer to the following questions in a draft
version of IOS 9899-99. What is the semantic when you decrement an
unsigned int below 0 (or subtract two unsigned ints with negative
result)? AFAIR, this results in implementation-defined behavior but
not undefined behavior. Is that correct?

So what does the standard say to this code?

void f(void)
{
unsigned int n = 0;
n--;
}

Also, do I have implementation-defined or undefined behavior, if I
decrement below zero but don't use the value, as in the following
code?

void f(unsigned int n)
{
while (n-- > 0) { /* In the last loop iteration, n is
; decremented from 0, but not used
} afterwards */
}

A short notice with section number in the standard would be nice
(as I think section numbering in my draft version is not that
different).

urs
 
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
int*unsigned int = unsigned? ciccio C++ 2 06-04-2010 01:54 PM
Negative values in unsigned int Urs Thuermann C Programming 15 09-19-2008 01:43 AM
is vec.reserve(unsigned int) better than vec(unsigned int)? er C++ 6 09-14-2007 06:20 AM
unsigned int const does not match const unsigned int Timo Freiberger C++ 3 10-30-2004 07:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57