Board index » cppbuilder » 64 bit ints under BCB5.0

64 bit ints under BCB5.0


2007-12-03 03:36:36 AM
cppbuilder6
The question (in my mind) how do you properly specify logical bit
operations with 64bit integers in BCB 5? There is a long extension
perhaps Long long (ll)?
I'm concerned as to what will happen if I do something like this
(_addr & 0xFF) where _addr is a unsigned __int64. The behavior of the
compiler in this instance is undefined as far as I can tell. It could
create a literal of arbitrary type and then perform either a 64bit and
or a 32 bit and. Either way it would give the wrong results (IE
promoting 0xFF to a 64 bit value would it 0 pad the most significant
double word or use whatever would be there other wise (ie like it were a
type cast which would allow whatever data besides a long int to be used
as the Most Signicant Double Word.)
So what is the best way? To be certain the data isn't mangled in some
strange way (which has happened in prior instances of using BCB for me :) ).
Sadly all I want to do is _addr & 0xFF (get only the 8 least signicant
bits).
Stephen
 
 

Re:64 bit ints under BCB5.0

Quote
... (_addr & 0xFF) where _addr is a unsigned __int64 ...
The result of that is an unsigned __int64 where all but the lower bits are
forced to zero and the lower 8 bits are unchanged from what they are in
_addr.
If you fear the compiler may mess up the type conversions you could always
specify a different type for the literal such as
result = _addr & 0xFFui64;
You might also try this:
(unsigned char) _addr // byte variable with the lower 8 bits of _addr
or if you insist on C++ style casts
result = static_cast<unsigned char>(_addr);
. Ed
Quote
Stephen R. Phillips wrote in message
news:4752fb9a$ XXXX@XXXXX.COM ...

The question (in my mind) how do you properly specify logical bit
operations with 64bit integers in BCB 5? There is a long extension perhaps
Long long (ll)?

I'm concerned as to what will happen if I do something like this
(_addr & 0xFF) where _addr is a unsigned __int64. The behavior of the
compiler in this instance is undefined as far as I can tell. It could
create a literal of arbitrary type and then perform either a 64bit and or
a 32 bit and. Either way it would give the wrong results (IE promoting
0xFF to a 64 bit value would it 0 pad the most significant double word or
use whatever would be there other wise (ie like it were a type cast which
would allow whatever data besides a long int to be used as the Most
Signicant Double Word.)
So what is the best way? To be certain the data isn't mangled in some
strange way (which has happened in prior instances of using BCB for me
:) ).

Sadly all I want to do is _addr & 0xFF (get only the 8 least signicant
bits).
 

Re:64 bit ints under BCB5.0

Ed Mulroy [TeamB] wrote:
Quote
>... (_addr & 0xFF) where _addr is a unsigned __int64 ...

The result of that is an unsigned __int64 where all but the lower bits are
forced to zero and the lower 8 bits are unchanged from what they are in
_addr.

If you fear the compiler may mess up the type conversions you could always
specify a different type for the literal such as
result = _addr & 0xFFui64;
I was wondering how one could specify a number as __int64.

You might also try this:
(unsigned char) _addr // byte variable with the lower 8 bits of _addr

(face palm) I hadn't thought of type casting. That is likely a much
safer route.
Quote
or if you insist on C++ style casts
result = static_cast<unsigned char>(_addr);

Hmm I can test both.
Stephen
 

{smallsort}