Release vs Debug Why does this not work 
Author Message
 Release vs Debug Why does this not work

I have a real simple program which I would expect to output the value 2
which it does in debug mode but when I use the release mode I get 0.  Can
anybody explain to me what is going on here?Could it be a bug?  I am using
C++ 6 with service Pack 2.  I have not tried this with C++ 5 but I will
soon.

Thanks for your help

Nick

#include <stdio.h>
#include <malloc.h>

long Height =2;
main()
{
        static long *Test;
        int i;
        long *pHeight;
        Test = (long *)malloc(10*sizeof(long));
        for(i=0;i<10;++i)
        {
                Test[i]=i;
        }
        pHeight = &Height;
        printf("Test[Height *2] - Test[Height] = %d", Test[Height *2] -
Test[Height]);
        free(Test);

Quote:
}



Sun, 26 Aug 2001 03:00:00 GMT  
 Release vs Debug Why does this not work

Quote:

>I have a real simple program which I would expect to output the value 2
>which it does in debug mode but when I use the release mode I get 0.  Can
>anybody explain to me what is going on here?Could it be a bug?

Looks like a bug to me.

Quote:
>I am using
>C++ 6 with service Pack 2.  I have not tried this with C++ 5 but I will
>soon.

>Thanks for your help

>Nick

>#include <stdio.h>
>#include <malloc.h>

>long Height =2;
>main()
>{
> static long *Test;
> int i;
> long *pHeight;
> Test = (long *)malloc(10*sizeof(long));
> for(i=0;i<10;++i)
> {
> Test[i]=i;
> }
> pHeight = &Height;
> printf("Test[Height *2] - Test[Height] = %d", Test[Height *2] - Test[Height]);

The following code is generated with /O1 switch for above line:


        mov     edx, DWORD PTR [eax+ecx*8]
        sub     edx, edx
        push    edx

        call    _printf

Note that address for the edx load points to
the (Height * 2) element and the offset of the
(Height) element is not calculated.  The 0
comes from the sub edx, edx line.  It looks
like the optimizer treated the indexing
expressions as identical.  A similar error
occurs with a /O2 switch.

Quote:
> free(Test);

>}

--Larry Brasfield
Above opinions may be mine alone.



Sun, 26 Aug 2001 03:00:00 GMT  
 Release vs Debug Why does this not work
Well, I was able to recreate it using the same setup as you.  If you change
the release build optimization to default it will work.  Go figure.
Quote:

>I have a real simple program which I would expect to output the value 2
>which it does in debug mode but when I use the release mode I get 0.  Can
>anybody explain to me what is going on here?Could it be a bug?  I am using
>C++ 6 with service Pack 2.  I have not tried this with C++ 5 but I will
>soon.

>Thanks for your help

>Nick

>#include <stdio.h>
>#include <malloc.h>

>long Height =2;
>main()
>{
> static long *Test;
> int i;
> long *pHeight;
> Test = (long *)malloc(10*sizeof(long));
> for(i=0;i<10;++i)
> {
> Test[i]=i;
> }
> pHeight = &Height;
> printf("Test[Height *2] - Test[Height] = %d", Test[Height *2] -
>Test[Height]);
> free(Test);

>}



Sun, 26 Aug 2001 03:00:00 GMT  
 Release vs Debug Why does this not work
    The code beeing generated is wrong, one possible change to make this
work is changing the Height to a cosnt.

bad code:
31:       printf("Test[Height *2] - Test[Height] = %ld\n", Test[Height *
2] - Test[Height]);
004010A1   mov         eax,[Test (00403084)]
004010A6   mov         ecx,dword ptr [Height (00403020)]
004010AC   push        esi
004010AD   push        edi
004010AE   mov         edx,dword ptr [eax+ecx*8]
004010B1   mov         edi,edx
<-- Error is here
004010B3   sub         edx,edi
004010B5   mov         edi,dword ptr [__imp__printf (0040204c)]
004010BB   push        edx
004010BC   push        offset string "Test[Height *2] - Test[Height] ="...
(00403034)
004010C1   call        edi
004010C3   add         esp,8
good code:
31:       printf("Test[Height *2] - Test[Height] = %ld\n", Test[Height *
2] - Test[Height]);
004010A1   mov         eax,[Test (00403074)]
004010A6   push        esi
004010A7   push        edi
004010A8   mov         edx,dword ptr [eax+10h]
004010AB   mov         edi,dword ptr [eax+8]
004010AE   sub         edx,edi
004010B0   mov         edi,dword ptr [__imp__printf (0040204c)]
004010B6   push        edx
004010B7   push        offset string "Test[Height *2] - Test[Height] ="...
(00403030)
004010BC   call        edi
004010BE   add         esp,8

    The compiler is generating Test[Height * 2] as it was Test[Height]
    Jacques

Quote:

>I have a real simple program which I would expect to output the value 2
>which it does in debug mode but when I use the release mode I get 0.  Can
>anybody explain to me what is going on here?Could it be a bug?  I am using
>C++ 6 with service Pack 2.  I have not tried this with C++ 5 but I will
>soon.

>Thanks for your help

>Nick

>#include <stdio.h>
>#include <malloc.h>

>long Height =2;
>main()
>{
> static long *Test;
> int i;
> long *pHeight;
> Test = (long *)malloc(10*sizeof(long));
> for(i=0;i<10;++i)
> {
> Test[i]=i;
> }
> pHeight = &Height;
> printf("Test[Height *2] - Test[Height] = %d", Test[Height *2] -
>Test[Height]);
> free(Test);

>}



Sun, 26 Aug 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Program not work at release mode but work at debug mode

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

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

4. Works in Debug mode but not in Release mode

5. Works in debug but not in release

6. Works in debug version, not in release - CryptoAPI _ATL_MIN_CRT

7. works in debug but not release

8. Works in debug mode but not in release

9. extended stored procedure working in debug mode but not in release

10. STRCPY does not work in debug, Ok in release build

11. Works in debug but not in release, help

12. try-catch works in Debug but not Release

 

 
Powered by phpBB® Forum Software