This is perhaps a basic question, but it's been a while since I've
done C, and none of the searches I did on operators and data types
wanted to address this, so here goes...
In the glibc (linux) library, I found this expression , and I want to
know exactly what it's doing.
res >= 0xfffff001u
Here, res is an int. It looks to me like res is being interpreted as
an unsigned int (long?) and then being compared against the constant
(-4095). So if res happens to be, say, -22, this expression will be
true. If res happens to be -4096, this statement will be false, maybe?
Is that right?
:)
-Corinna 4 1493
swansnow wrote:
This is perhaps a basic question, but it's been a while since I've
done C, and none of the searches I did on operators and data types
wanted to address this, so here goes...
In the glibc (linux) library, I found this expression , and I want to
know exactly what it's doing.
res >= 0xfffff001u
Here, res is an int. It looks to me like res is being interpreted as
an unsigned int (long?) and then being compared against the constant
(-4095). So if res happens to be, say, -22, this expression will be
true. If res happens to be -4096, this statement will be false, maybe?
Is that right?
It depends very much upon the value of INT_MAX and UINT_MAX. If INT_MAX
0xfffff001u, then the constant will be promoted to an int before
performing the comparison. As a result, the comparison will be done as a
signed comparison, and only very large positive values of res will pass
the test. If, on the other hand, INT_MAX < 0xfffff001u, then res will be
converted to the same type as the constant (which will be either
unsigned int or unsigned long, depending upon whether or not UINT_MAX >
0xfffff01u). The exact result you get will depend upon the results of
that conversion.
James Kuyper <jameskuy...@verizon.netwrote:
swansnow wrote:
In the glibc (linux) library, I found this expression ,
and I want to know exactly what it's doing.
res >= 0xfffff001u
Here, res is an int. It looks to me like res is being
interpreted as an unsigned int (long?)
If 0xfffff001u <= UINT_MAX, it's equivalent to...
(unsigned) res >= 0xfffff001u
Otherwise it's equivalent to...
(unsigned long) res >= 0xfffff001u
and then being compared against the constant (-4095).
So if res happens to be, say, -22, this expression will
be true. If res happens to be -4096, this statement
will be false, maybe?
Is that right?
It depends very much upon the value of INT_MAX and
UINT_MAX.
I think you've misremembered.
If INT_MAX 0xfffff001u, then the constant will be
promoted to an int before performing the comparison.
Not according to 6.4.4.1p5. The u suffix means it is
an unsigned integer; at least an unsigned int, but
possibly a wider (higher rank). It's certainly not a
lower rank than unsigned int though. E.g. (1 -1u)
is never true.
--
Peter
Peter Nilsson wrote:
....
I think you've misremembered.
Yes, you're right. I actually thought to myself "I'd better double check
before I post", and then decided not to. :-(
Thanks for the clarification. I was starting to worry... :)
On Dec 11, 6:24 pm, Peter Nilsson <ai...@acay.com.auwrote:
If 0xfffff001u <= UINT_MAX, it's equivalent to...
(unsigned) res >= 0xfffff001u
Otherwise it's equivalent to...
(unsigned long) res >= 0xfffff001u This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Zenon |
last post by:
Folks,
I am having a terrible time overloading operators. I have tried what
I thought was the correct way, I tried the cheating (friend
declarations), all to no avail. Sorry for posting tons of...
|
by: BigMan |
last post by:
Can someone cite the rules for type promotion in C++?
And, in particular, what is the type of the result of adding 2 values
of type char?
|
by: charles_gero |
last post by:
Hi all,
I had a question about the topics in the subject and posted to
comp.std.c, but feel it may also be appropriate here. Please excuse
this crosspost if it is in bad form.
I have a...
|
by: dogbert1793 |
last post by:
Consider the code:
unsigned char uc;
cout << "sizeof( unsigned char ) = " << sizeof( uc ) << endl;
cout << "sizeof( ~unsigned char ) = " << sizeof( ~uc ) << endl;
Why is the output:
...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |