Supposedly Working Code

Discussion in 'C++' started by KevinSimonson, Oct 22, 2010.

  1. 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%28VS.
    80%29.aspx" and "http://msdn.microsoft.com/en-us/library/wfd9z0bb%28VS.
    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
     
    KevinSimonson, Oct 22, 2010
    #1
    1. Advertising

  2. KevinSimonson

    Ian Collins Guest

    On 10/23/10 11:43 AM, KevinSimonson wrote:
    > 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%28VS.
    > 80%29.aspx" and "http://msdn.microsoft.com/en-us/library/wfd9z0bb%28VS.
    > 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.

    --
    Ian Collins
     
    Ian Collins, Oct 22, 2010
    #2
    1. Advertising

  3. KevinSimonson

    Geoff Guest

    On Sat, 23 Oct 2010 11:53:16 +1300, Ian Collins <>
    wrote:

    >On 10/23/10 11:43 AM, KevinSimonson wrote:
    >> 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%28VS.
    >> 80%29.aspx" and "http://msdn.microsoft.com/en-us/library/wfd9z0bb%28VS.
    >> 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.


    In Windows, DWORD is a typedef for unsigned long.

    >
    >> 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.


    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.
     
    Geoff, Oct 23, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ratman
    Replies:
    0
    Views:
    676
    Ratman
    Sep 14, 2004
  2. jason
    Replies:
    4
    Views:
    2,658
    jason
    Jun 2, 2005
  3. Peri
    Replies:
    2
    Views:
    2,979
  4. David. E. Goble
    Replies:
    9
    Views:
    491
    David. E. Goble
    Feb 2, 2005
  5. SG
    Replies:
    4
    Views:
    324
Loading...

Share This Page