#### Archived

This topic is now archived and is closed to further replies.

# wierd optimization action....

This topic is 5029 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey Im having a bit of trouble with visual studio 6. Ive got a basic window shell im compiling...compiles fine in a debug compile, but with the release compile with the speed optimizations on, and you open the exe not from visual studio but from windows it just closes as soon as it opens. Its wierd. Id really like to see if I messed up with my code or is it the compiler. Im pretty confused. Heres the zip with the source and binaries....thanks http://www.ngforce.com/win3201.zip

##### Share on other sites
I have downloaded your source code, and ran your Release.exe. There was no problem there. I also ran it through MSVC++ in release mode, and again, no problems.

Does it work properly in debug mode on your machine??. If not, make a break point and debug it step-by-step. Then when the error occurs, you can tell what function, or pointer, etc is causing the problem.

Im sorry I cant be of more help, but I dont seem to be having this problem

- Ratterbox

[edited by - Ratterbox on May 18, 2004 6:15:24 AM]

##### Share on other sites
The debug works flawless on my machine...i have used breakpoints through my message loop....no problems runs fine...It might just be my computer I dont know I never had this problem before.

##### Share on other sites
hmm.. works for me too (win2k3)

##### Share on other sites
I have installed visual studio service pack 6....compiles a slightly larger exe and runs normally...guess that fixed it? lol whatever theres some microsoft software at work....:D

##### Share on other sites
Er.

I haven''t had a look at your code, but console apps usually close when they''re done executing in Windows. MSVC adds a "Hit any key to continue" at the end of program execution to allow you to see what happens.

If that''s the case, add a getch(); at the end of your program.

##### Share on other sites
quote:
Original post by RuneLancer
I haven''t had a look at your code, but console apps usually close when they''re done executing in Windows. MSVC adds a "Hit any key to continue" at the end of program execution to allow you to see what happens.

Duh! ''Console apps'' are intended to be run from a pre-existing console.

quote:
If that''s the case, add a getch(); at the end of your program.

Bad idea. You''re better off creating a .pif file for your app.

##### Share on other sites
quote:
Original post by Fruny
quote:
If that''s the case, add a getch(); at the end of your program.

Bad idea. You''re better off creating a .pif file for your app.

Care to elaborate?

##### Share on other sites
system("pause");

command to the end of your program...

##### Share on other sites
This was a windows program. When I comiled with the speed optimizations on the program crashed as soon as it launched, but on the debug compiled exe it ran fine. This stopped happening when I installed service pack 6 for visual studio 6....I also had some wierd action with my resource scripts not compiling before I updated...anyone else have simular issues with XP and visual studio? Again everything seemed to be fixed after I updated it...

##### Share on other sites
Differences between debug and release mode are usually caused due to (not) initialized variables.

In debug-mode, all variables are usually initialized automatically, but on release mode they just stay unchanged.

check your code for such cases, helps most of the time.

##### Share on other sites
quote:
Original post by RuneLancer
quote:
Original post by Fruny
Bad idea. You''re better off creating a .pif file for your app.

Care to elaborate?

PIF files are files that are/were used to control properties of DOS programs when run in Windows - though you can use them to some extent with windows console apps. These properties include, among other things ''Close window on exit''. Even if you don''t use that, it is trivial to create an auxiliary program (e.g. a batch file) that will call your console app and add a pause at the end:

MyProg.batMyProg.exePAUSE

If you add a getch() or system("pause") or whatever at the end of your program, you will get that ''interruption'' of the program flow even if you use it within a standalone console (start command.com/cmd.exe then call your program from there) or if you use it within a shell script.

Keeping that interactive ''junk IO'' outside of your main program is a Good Thing in my book.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan