Different arithmetics for debug and release version? 
Author Message
 Different arithmetics for debug and release version?

I'm using Visual C++ 6.0 with Service Pack 5 applied.

Write the following program in a console project,

        #include <iostream>

        int main()
        {
                unsigned int x = 32;
                const unsigned int cx = 32;
                std::cout << (1 << x) << std::endl;
                std::cout << (1 << cx) << std::endl;
                return 0;
        }

and you'll get different results for the debug and release version.

        Debug:  Release:
        1       0
        0       0

Is it a bug?

--



Fri, 27 May 2005 12:57:15 GMT  
 Different arithmetics for debug and release version?

Quote:

>I'm using Visual C++ 6.0 with Service Pack 5 applied.

>Write the following program in a console project,

>    #include <iostream>

>    int main()
>    {
>            unsigned int x = 32;
>            const unsigned int cx = 32;
>            std::cout << (1 << x) << std::endl;
>            std::cout << (1 << cx) << std::endl;
>            return 0;
>    }

>and you'll get different results for the debug and release version.

>    Debug:  Release:
>    1       0
>    0       0

>Is it a bug?

No. It's undefined to shift an integer by an amount >= to the number of bits
in the integer. This means you can't expect any particular answer or
behavior.

--
Doug Harrison
Microsoft MVP - Visual C++



Fri, 27 May 2005 13:13:42 GMT  
 Different arithmetics for debug and release version?
Yes, it's a bug in *your* program :-)

It is undefined behaviour to do a shift of 32, on a 32bit integer
(or a shift of x, where x is the size in bits of the type your are
shifting).

James


Quote:
> I'm using Visual C++ 6.0 with Service Pack 5 applied.

> Write the following program in a console project,

> #include <iostream>

> int main()
> {
> unsigned int x = 32;
> const unsigned int cx = 32;
> std::cout << (1 << x) << std::endl;
> std::cout << (1 << cx) << std::endl;
> return 0;
> }

> and you'll get different results for the debug and release version.

> Debug: Release:
> 1 0
> 0 0

> Is it a bug?

> --




Sat, 28 May 2005 00:44:49 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Different execution between Release and Debug version

2. Dll's with different names for debug-/release-Version

3. different calculations in debug and release version ?

4. Different debug vs release version

5. Debug version - Release version

6. Debug version ok but release version problem

7. Debug Version and Release Version

8. Win32 debug version and Win32 release version

9. Why the Font size is not same between Debug version and Release Version

10. Debug version Ok, Release version Failed

11. Debug version ok but release version problem

12. Debug version works, Release version does not?!

 

 
Powered by phpBB® Forum Software