((UINT)-1)

J

Jure Sah

Hello,

I am making an application in assembly, however all my API reference is
written for C. I need the binary layout of a specific flag, however it
is defined as:

define WAVE_MAPPER ((UINT)-1)

And this makes no sense to me whatsoever. How does one typecast -1 into
a type that doesn't support negative values? How does this value look in
binary?

Thank you for your help in advance.

--
Primary function: Coprocessor
Secondary function: Cluster commander

"It works, sort of."
-- Xerox Labs, 1973

01010010 01100101 01110011 01101001 01100100 01100101 01101110 01110100
01000010 01000001 01010011 01001001 01000011
 
J

Jim Langston

Jure Sah said:
Hello,

I am making an application in assembly, however all my API reference is
written for C. I need the binary layout of a specific flag, however it is
defined as:

define WAVE_MAPPER ((UINT)-1)

And this makes no sense to me whatsoever. How does one typecast -1 into a
type that doesn't support negative values? How does this value look in
binary?

Thank you for your help in advance.

All bits set. For 8 4 byte ints it's 0xFFFFFFFF;

-1 in two's compliment is all bits set, and in an unsigned integer it would
be the maximum value it could store.
 
T

Thomas J. Gritzan

Jure said:
Hello,

I am making an application in assembly, however all my API reference is
written for C.

This is a C++ newsgroup.
I need the binary layout of a specific flag, however it
is defined as:

define WAVE_MAPPER ((UINT)-1)
#define


And this makes no sense to me whatsoever. How does one typecast -1 into
a type that doesn't support negative values? How does this value look in
binary?

Undefined in C++.

<offtopic>
Usually, the bit-pattern of the -1 will be reinterpreted as unsigned value.
For implementations that use two's complement, it would be all-bits-one:
http://en.wikipedia.org/wiki/Two's_complement
</offtopic>
 
F

Frederick Gotham

Jure Sah posted:
define WAVE_MAPPER ((UINT)-1)


Across all implementations (both C and C++), irrespective of whether the
architecture uses One's Complement, Two's Complement or Sign-magnitude, the
result of converting a negative integer value to an unsigned integer type is
well-defined, and has an identical effect on every implementation.

It has the effect of setting the unsigned integer type to its maximum value
on that implementation:

#include <climits>
#include <cassert>

int main()
{
assert( UCHAR_MAX == (char unsigned)-1 );
assert( USHRT_MAX == (short unsigned)-1 );
assert( UINT_MAX == (unsigned)-1 );
assert( ULONG_MAX == (long unsigned)-1 );
}

You may also notice that the highest value for an unsigned integer type is
also the bit pattern of "all bits one".
 
C

Clark S. Cox III

Thomas said:
This is a C++ newsgroup.


Undefined in C++.

No, it is not undefined in C++ (or C). Casting -1 to an unsigned type
will *always* yield the maximum value that that unsigned type can
represent.
 
R

Ron Natalie

Thomas said:
Undefined in C++.

<offtopic>
Usually, the bit-pattern of the -1 will be reinterpreted as unsigned value.
For implementations that use two's complement, it would be all-bits-one:
http://en.wikipedia.org/wiki/Two's_complement
</offtopic>
It is not uNDEFINED and it has squat to do with the bit pattern. This
is only effectively a static cast because a signed int can be converted
to an unsigned int. The rules requires that the number be wrapped
modulo 2**number_of_bits (which effectively is the same as using the
direct 2's complement value).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,005
Messages
2,570,264
Members
46,859
Latest member
HeidiAtkin

Latest Threads

Top