Supposedly Working Code

K

KevinSimonson

I'm currently trying to use Visual Studio 2010 to build Shareaza, a
piece of open source software that theoretically should just build
from the C++ files without any problems. But when I attempted to
build it I got the following two error messages:

1>c:\<path-name>\shareaza\hashlib\utility.hpp(348): error C2664:
'_BitScanReverse' : cannot convert parameter 1 from 'uint32 *' to
'DWORD *'
1> Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
1>c:\<path-name>\shareaza\hashlib\utility.hpp(370): error C2664:
'_BitScanForward' : cannot convert parameter 1 from 'uint32 *' to
'DWORD *'
1> Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
1>
1>Build FAILED.

I took a look at the vicinity of lines 348 and 370 and got

345: inline uint32 highestBitSet(uint32 value)
346: {
347: uint32 index;
348: return _BitScanReverse( &index, value ) ? index : 0;
349: }

and

367: inline uint32 lowestBitSet(uint32 value)
368: {
369: uint32 index;
370: return _BitScanForward( &index, value ) ? index : 0;
371: }

and I looked <_BitScanReverse()> and <_BitScanForward()> up on the
Internet (at "http://msdn.microsoft.com/en-us/library/fbxyd7zd(VS.
80%29.aspx" and "http://msdn.microsoft.com/en-us/library/wfd9z0bb(VS.
80%29.aspx") and got:

unsigned char _BitScanReverse(
unsigned long * Index,
unsigned long Mask
);

and

unsigned char _BitScanForward(
unsigned long * Index,
unsigned long Mask
);

In view of these definitions, can anyone tell me (1) why this code is
generating these error messages, and (2) if it should be generating
these error messages, why it could _ever_ have compiled on _any_ C++
compiler. I remind you that I copied this code from an open source
repository; theoretically this code has already been compiled to
generate a working executable.

I look at this code and I think, all I really have to do is change the
type of each <index> variable from <unit32> to <unsigned long>. Is
that naive? Might I run into some unforeseen problems if I do that?
I'm a little hesitant to tweak the code, since I've been led to
believe that it was supposed to be working code before I downloaded
it. So what do you think? Should I tweak the code or should I try to
find some _other_ way to get this code working?

Kevin S
 
I

Ian Collins

I'm currently trying to use Visual Studio 2010 to build Shareaza, a
piece of open source software that theoretically should just build
from the C++ files without any problems. But when I attempted to
build it I got the following two error messages:

1>c:\<path-name>\shareaza\hashlib\utility.hpp(348): error C2664:
'_BitScanReverse' : cannot convert parameter 1 from 'uint32 *' to
'DWORD *'
1> Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
1>c:\<path-name>\shareaza\hashlib\utility.hpp(370): error C2664:
'_BitScanForward' : cannot convert parameter 1 from 'uint32 *' to
'DWORD *'
1> Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
1>
1>Build FAILED.

I took a look at the vicinity of lines 348 and 370 and got

345: inline uint32 highestBitSet(uint32 value)
346: {
347: uint32 index;
348: return _BitScanReverse(&index, value ) ? index : 0;
349: }

and

367: inline uint32 lowestBitSet(uint32 value)
368: {
369: uint32 index;
370: return _BitScanForward(&index, value ) ? index : 0;
371: }

and I looked<_BitScanReverse()> and<_BitScanForward()> up on the
Internet (at "http://msdn.microsoft.com/en-us/library/fbxyd7zd(VS.
80%29.aspx" and "http://msdn.microsoft.com/en-us/library/wfd9z0bb(VS.
80%29.aspx") and got:

unsigned char _BitScanReverse(
unsigned long * Index,
unsigned long Mask
);

and

unsigned char _BitScanForward(
unsigned long * Index,
unsigned long Mask
);

In view of these definitions, can anyone tell me (1) why this code is
generating these error messages, and (2) if it should be generating
these error messages, why it could _ever_ have compiled on _any_ C++
compiler. I remind you that I copied this code from an open source
repository; theoretically this code has already been compiled to
generate a working executable.

The code is a bit wanky, mixing fixed with types and standard integral
types is never a good idea. The relative widths of these types my vary
across platforms and there's certainly no guarantee their pointers will
be compatible. Although why the prototype parameter is "unsigned long*"
and the error says "DWORD*" is rather odd.
I look at this code and I think, all I really have to do is change the
type of each<index> variable from<unit32> to<unsigned long>. Is
that naive? Might I run into some unforeseen problems if I do that?
I'm a little hesitant to tweak the code, since I've been led to
believe that it was supposed to be working code before I downloaded
it. So what do you think? Should I tweak the code or should I try to
find some _other_ way to get this code working?

Have a look and how they define "unit32" would be a good start.
 
G

Geoff

The code is a bit wanky, mixing fixed with types and standard integral
types is never a good idea. The relative widths of these types my vary
across platforms and there's certainly no guarantee their pointers will
be compatible. Although why the prototype parameter is "unsigned long*"
and the error says "DWORD*" is rather odd.

In Windows, DWORD is a typedef for unsigned long.
Have a look and how they define "unit32" would be a good start.

It's uint32, not unit32 but I suspect propagation of typos here. In
boost, uint32 is typedef of uint32_t and it is a typedef for unsigned
int, thus no conversion exists for unsigned long to unsigned int.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top