when i do a.....
________________________________________________
unsigned int iTest; // lets asume 'int' = 32bit
iTest = 0xFFFFFFFF;
iTest++;
________________________________________________
does the std say something what shall happen now?
May i safely assume iTest is now 0 or is it CPU or sys-dependent?
TIA, ~.rhavin;) 13 1449
..rhavin grobert wrote:
when i do a.....
________________________________________________
unsigned int iTest; // lets asume 'int' = 32bit
iTest = 0xFFFFFFFF;
iTest++;
________________________________________________
does the std say something what shall happen now?
May i safely assume iTest is now 0 or is it CPU or sys-dependent?
TIA, ~.rhavin;)
the second one.
best, zeppe
On 21 Okt., 17:57, Zeppe <ze...@remove.all.this.long.comment.yahoo.it>
wrote:
.rhavin grobert wrote:
when i do a.....
________________________________________________
unsigned int iTest; * *// lets asume 'int' = 32bit
iTest = 0xFFFFFFFF;
iTest++;
________________________________________________
does the std say something what shall happen now?
May i safely assume iTest is now 0 or is it CPU or sys-dependent?
TIA, ~.rhavin;)
the second one.
best, zeppe
CPU-dependent? damn, that's the worst case!
On Oct 21, 11:57*am, Zeppe
<ze...@remove.all.this.long.comment.yahoo.itwrot e:
.rhavin grobert wrote:
when i do a.....
________________________________________________
unsigned int iTest; * *// lets asume 'int' = 32bit
iTest = 0xFFFFFFFF;
iTest++;
________________________________________________
does the std say something what shall happen now?
May i safely assume iTest is now 0 or is it CPU or sys-dependent?
TIA, ~.rhavin;)
the second one.
best, zeppe
That is incorrect. Assuming unsigned int is 32-bits, result will
always be 0.
REH
On Oct 21, 4:57*pm, Zeppe
<ze...@remove.all.this.long.comment.yahoo.itwrot e:
.rhavin grobert wrote:
when i do a.....
________________________________________________
unsigned int iTest; * *// lets asume 'int' = 32bit
iTest = 0xFFFFFFFF;
iTest++;
________________________________________________
does the std say something what shall happen now?
May i safely assume iTest is now 0 or is it CPU or sys-dependent?
TIA, ~.rhavin;)
the second one.
Wrong answer.
The C and C++ standards guarantee the wrapping for unsigned integer
types.
Here is a relevant quote from C99 6.2.5:
A computation involving unsigned operands can never overflow, because
a result that cannot be represented by the resulting unsigned integer
type is reduced modulo the number that is one greater than the largest
value that can be represented by the resulting type.
--
Max
Maxim Yegorushkin wrote:
[..]
The C and C++ standards guarantee the wrapping for unsigned integer
types.
Here is a relevant quote from C99 6.2.5:
[..]
Why C99? C++ has its own Standard, does it not?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Tue, 21 Oct 2008 09:27:47 -0700, Maxim Yegorushkin wrote:
>.rhavin grobert wrote:
when i do a.....
________________________________________________
unsigned int iTest; Â* Â*// lets asume 'int' = 32bit
iTest = 0xFFFFFFFF;
iTest++;
________________________________________________
does the std say something what shall happen now?
May i safely assume iTest is now 0 or is it CPU or sys-dependent?
TIA, ~.rhavin;)
the second one.
Wrong answer.
The C and C++ standards guarantee the wrapping for unsigned integer types.
Here is a relevant quote from C99 6.2.5:
A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.
Sure C++ has a C legacy, but quoting the C standard
in a C++ context just looks wrong, even if the actual
text is almost the same.
--
OU
Remember 18th of June 2008, Democracy died that afternoon. http://frapedia.se/wiki/Information_in_English
On 2008-10-21 18:49, Victor Bazarov wrote:
Maxim Yegorushkin wrote:
>[..] The C and C++ standards guarantee the wrapping for unsigned integer types.
Here is a relevant quote from C99 6.2.5: [..]
Why C99? C++ has its own Standard, does it not?
For your pleasure:
3.9.1/4:
"Unsigned integers, declared unsigned, shall obey the laws of arithmetic
modulo 2^n where n is the number of bits in the value representation of
that particular size of integer."
--
Erik Wikström
Maxim Yegorushkin wrote:
>>______________________________________________ __ unsigned int iTest; // lets asume 'int' = 32bit iTest = 0xFFFFFFFF; iTest++; ______________________________________________ __ does the std say something what shall happen now? May i safely assume iTest is now 0 or is it CPU or sys-dependent? TIA, ~.rhavin;)
the second one.
Wrong answer.
The C and C++ standards guarantee the wrapping for unsigned integer
types.
My bad. Actually, I know that piece, I just ignored the comment as a
compiler would do. So, the result IS sys-dependent, BUT if you assume
that all the systems in which that code will be compiled are going to be
32bit, then is safe to assume that iTest is going to be zero after the
increment.
Sorry about that.
Best wishes,
Zeppe
In article <gd**********@aioe.org>, Zeppe
<ze***@remove.all.this.long.comment.yahoo.itwrot e:
Maxim Yegorushkin wrote:
>_______________________________________________ _ unsigned int iTest; // lets asume 'int' = 32bit iTest = 0xFFFFFFFF; iTest++; _______________________________________________ _ does the std say something what shall happen now? May i safely assume iTest is now 0 or is it CPU or sys-dependent? TIA, ~.rhavin;)
the second one.
Wrong answer.
The C and C++ standards guarantee the wrapping for unsigned integer
types.
My bad. Actually, I know that piece, I just ignored the comment as a
compiler would do. So, the result IS sys-dependent, BUT if you assume
that all the systems in which that code will be compiled are going to be
32bit, then is safe to assume that iTest is going to be zero after the
increment.
How about this:
unsigned i = UINT_MAX;
i++;
assert( i == 0 );
On 21 Okt., 20:23, blargg....@gishpuppy.com (blargg) wrote:
In article <gdl4cv$28...@aioe.org>, Zeppe
<ze...@remove.all.this.long.comment.yahoo.itwrot e:
Maxim Yegorushkin wrote:
>>______________________________________________ __
>>unsigned int iTest; * *// lets asume 'int' = 32bit
>>iTest = 0xFFFFFFFF;
>>iTest++;
>>______________________________________________ __
>>does the std say something what shall happen now?
>>May i safely assume iTest is now 0 or is it CPU or sys-dependent?
>>TIA, ~.rhavin;)
>the second one.
Wrong answer.
The C and C++ standards guarantee the wrapping for unsigned integer
types.
My bad. Actually, I know that piece, I just ignored the comment as a
compiler would do. So, the result IS sys-dependent, BUT if you assume
that all the systems in which that code will be compiled are going to be
32bit, then is safe to assume that iTest is going to be zero after the
increment.
How about this:
* * unsigned i = UINT_MAX;
* * i++;
* * assert( i == 0 );
Actually it's that one:
________________________________
typedef unsigned __int64 QUAD;
class foo {
foo(): m_qSel(0) {};
public:
inline QUAD NextSelector() {return m_qSel++;};
private:
QUAD m_qSel;
};
".rhavin grobert" <cl***@yahoo.dekirjutas:
On 21 Okt., 20:23, blargg....@gishpuppy.com (blargg) wrote:
[...]
>How about this:
* * unsigned i = UINT_MAX; * * i++; * * assert( i == 0 );
Actually it's that one:
________________________________
typedef unsigned __int64 QUAD;
class foo {
foo(): m_qSel(0) {};
public:
inline QUAD NextSelector() {return m_qSel++;};
private:
QUAD m_qSel;
};
And you are wondering what happens when this wraps over? Let's see,
assuming for example million increments in a second(*), this happens ...
in approx. 9000 years! It's really reassuring to know the behavior will
be well-defined!
Paavo
(*) and assuming unsigned __int64 is an implementation-defined unsigned
64-bit integer type following the same rules as standard types.
..rhavin grobert wrote:
when i do a.....
________________________________________________
unsigned int iTest; // lets asume 'int' = 32bit
iTest = 0xFFFFFFFF;
iTest++;
________________________________________________
does the std say something what shall happen now?
May i safely assume iTest is now 0 or is it CPU or sys-dependent?
TIA, ~.rhavin;)
It is now 0 because it is unsigned and int is 32 bits.
Unsigned integer 'overflow' is always safe.
On 22 Okt., 08:57, Paavo Helde <nob...@ebi.eewrote:
".rhavin grobert" <cl...@yahoo.dekirjutas:
On 21 Okt., 20:23, blargg....@gishpuppy.com (blargg) wrote:
[...]
How about this:
* * unsigned i = UINT_MAX;
* * i++;
* * assert( i == 0 );
Actually it's that one:
________________________________
typedef unsigned __int64 QUAD;
class foo {
* foo(): m_qSel(0) {};
public:
* inline QUAD NextSelector() {return m_qSel++;};
private:
* QUAD m_qSel;
};
And you are wondering what happens when this wraps over? Let's see,
assuming for example million increments in a second(*), this happens ...
in approx. 9000 years! It's really reassuring to know the behavior will
be well-defined!
Paavo
(*) and assuming unsigned __int64 is an implementation-defined unsigned
64-bit integer type following the same rules as standard types.
*sigh* humans!
;-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: George Marsaglia |
last post by:
The essence of a multiply-with-carry RNG is to have
declarations in the RNG proc, such as
unsigned long mwc( ){
static unsigned long x = 123456789, c = 362436;
unsigned long long t, a =...
|
by: dam_fool_2003 |
last post by:
For int data type the default range starts from signed to unsigned. If
we don't want negative value we can force an unsigned value. The same
goes for long also.
But I don't understand why we have...
|
by: jacob navia |
last post by:
A signed int can contain up to 2Gig, 2 147 483 648, to be exact.
Since The Mars rovers landed, I have been storing the
photographs in two directories, Spirit and Opportunity. I had
more than 18...
|
by: mr_semantics |
last post by:
I have been reading about the practise of casting values to unsigned
char while using the <ctype.h> functions. For example,
c = toupper ((unsigned char) c);
Now I understand that the standard...
|
by: LuB |
last post by:
This isn't a C++ question per se ... but rather, I'm posting this bcs I
want the answer from a C++ language perspective. Hope that makes sense.
I was reading Peter van der Linden's "Expert C...
|
by: sposes |
last post by:
Im very much a newbie but perhaps somehone can help me. Ive been
searching for a way to convert a std::string to a unsigned char*
The situation is I have a function that wants a unsigned char*...
|
by: alf |
last post by:
Hi,
is it possible that due to OS crash or mysql itself crash or some e.g.
SCSI failure to lose all the data stored in the table (let's say million
of 1KB rows). In other words what is the worst...
|
by: Paulo Matos |
last post by:
Hello,
Is it safe to assume a size_t is an unsigned long? (is it forced by
the standard?)
Thank you,
Paulo Matos
|
by: marydeepthy |
last post by:
Hi,
In my function, I receive a value as unsigned int, and i need to check
if it is greater than a limit.
say for example,
limit = 1000;
the checking is performed like this:
if(limit<...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |