Sign in to follow this  
pTymN

VC80 Optimize for maximum speed bug

Recommended Posts

pTymN    464
 #include <windows.h> 
  
 int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, LPSTR acCmdLine, int iWinMode) 
 { 
      char acXYZPath[260]; 
      strcpy_s(acXYZPath, 260, &acCmdLine[1]); 
  
      return 0; 
 } 
If a place a breakpoint on return 0; and examine acXYZPath, it is 3 garbage chars + 0 + acCmdLine. (Be sure to supply a command line arg in Configuration Properties/Debugging/Command Arguments. I set mine to "foo"). If you enable debug info (C++/General/Debug Information format and Linker/Debugging/Generate Debug Info) in release mode with the optimizer set to "Maximize speed", are you able to reproduce the error that I see?

Share this post


Link to post
Share on other sites
Yann L    1802
And depending on how smart the optimizer is, it might have removed the entire strcpy_s call, since it might have recognized that you never use the result and the CRT function call has no side effects.

As MJP said, put in a message box and everything will work as expected. Debugging release code is a lot harder than debugging debug code, and should not be attempted by a beginner.

Share this post


Link to post
Share on other sites
brwarner    100
Why does the debugger have so much trouble in release mode? All strings are always offset and such, what real differences does it do to the code?

Share this post


Link to post
Share on other sites
crowley9    226
> Why does the debugger have so much trouble in release mode?
> All strings are always offset and such, what real differences does it do to the code?

What Yann L is getting at is that your code doesn't actually do anything, so therefore there is no reason to generate any code, or even create any of your strings.

Share this post


Link to post
Share on other sites
l0calh05t    1796
An easy way to check if the compiler actually produced the code for the call is to turn on assembly output. That is of course if you can read assembler code. But it's pretty unlikely that the compiler calls strcpy_s in this situtation because - as it has been mentioned - it has no side effects.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this