LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-08-2005, 07:01 AM   #1
Hady
Member
 
Registered: Nov 2003
Posts: 55

Rep: Reputation: 15
Compile C++ in Release vs. Debug Mode


Hi!

I hope someone could help me here since this is not related to Linux in any way.

I'm using Visual Studio 6.0:
My code is built with no erros and no warnings.

when I compile and run my code in Visual Studio 6.0 in Release Mode (Build -> Set Active Configuration -> Win32 Release)
my code runs perfectly fine!!

when I compile and run the SAME code in Debug Mode,
it crashes after some seconds!! I get a memory access violation!

I have a 1GB RAM on my pc, so I don't think I'm running out of memory here!!


I'd really really appreciate any help!
& Thanks in advance,

Hady
 
Old 06-08-2005, 07:35 AM   #2
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
That is something that I've run into as well. Do you have some kind of optimisations turned on for the release build (Project->Settings->C/C++ tab)? If so, it's possible that a dodgy piece of code is being optimised away somehow. Can you step through the code and identify where the crash occurs?

FWIW I think the "memory access violation" message is equivalent to "segmentation fault" in Linux coding, i.e. your program has tried to access memory outside of it's address space. This is very commonly caused by NULL pointers.
 
Old 06-08-2005, 08:00 AM   #3
Hady
Member
 
Registered: Nov 2003
Posts: 55

Original Poster
Rep: Reputation: 15
Hi & Thanks a lot for your reply.

You're right, I went through my code, it was a NULL pointer error! Now it's works correctly in Debug mode also!
Thanks!


by why when I have optimization "Maximum Speed" for Release mode,
it ignores NULL pointers?
Could you explain to me a bit about these optimization options?!

Thanks again!
 
Old 06-08-2005, 08:06 AM   #4
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
Well, I don't know any real details about how optimisation works. Basically, the compiler will alter the code in some way to make it either faster or smaller (depending on which optimisation is selected). I'd guess that what happened in this case was that the optimisations in some way changed the problem area of the code, so that it wasn't a problem. The error certainly wasn't being ignored, it was just never happening at all.
 
Old 06-08-2005, 09:20 AM   #5
Hady
Member
 
Registered: Nov 2003
Posts: 55

Original Poster
Rep: Reputation: 15
OK, Thanks trevelluk for your replies!
 
Old 06-09-2005, 11:59 AM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
I've run into the reverse problem at times. Code runs fine in debug mode, but crashes in release mode. I believe another thing that debug mode does, is to allocate extra space when creating arrays and such. So... when working in debug mode, often times accessing an array beyond its bounds will succeed, but then it will fail in release mode because that extra debug memory goes away. Anyway, not really the problem you are seeing, but it is something else to watch for...
 
Old 06-09-2005, 12:22 PM   #7
smallest
LQ Newbie
 
Registered: Jun 2005
Posts: 5

Rep: Reputation: 0
Quote:
Originally posted by Hady
Hi & Thanks a lot for your reply.
by why when I have optimization "Maximum Speed" for Release mode,
it ignores NULL pointers?
it doesn't.

uninitialized variables contiain random (unpredictable, at least) data. whatever random data was in the pointer during the debug build caused an access violation, but the random data in the release build didn't, but it could have - wherever it was pointing wasn't a place that the OS was worried about.

you just got lucky.

Last edited by smallest; 06-09-2005 at 12:23 PM.
 
Old 06-13-2005, 04:00 AM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
According to C++ standard, dereferencing bad pointers (NULL, uninitialized, or out of scope) is "undefined". That means that your implementation can throw an exception, do what "you meant to do", do something else, or do nothing at all. I've had the same problem with BCB6. Windows sometimes lets your program dereference a bad pointer and not throw an exception (especially when accessing int data members), but Linux is very good about letting you know when you've messed up.
ta0kira

Last edited by ta0kira; 06-13-2005 at 04:02 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SUSE Release 10 RC1 Release Candidate 1 available 1kyle SUSE / openSUSE 8 09-11-2005 06:26 PM
Quake II stuck in debug mode shortname Linux - Games 1 05-09-2005 08:28 PM
How can I change display mode from character mode to graph mode wuzhong Linux - Hardware 1 08-08-2004 09:36 AM
[debug]what does the following debug information mean icoming Programming 21 06-08-2004 02:13 AM
DHCP in debug mode lapthorn Linux - Networking 1 12-03-2003 07:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration