Sign in to follow this  
AncientPC

Why does my program crash with one compiler and not another?

Recommended Posts

I prefer to use PSPad (basically a glorified Notepad) to write my code and complie it with Borland C++ 5.0 since it's open source. My program reads in data from a file, processes it, then stores it in an vector of objects. The program crashes when I read in 27 lines. I then switched over to CodeWarrior so I can debug and step through my program. To my surprise, the program works completely fine irregardless of how many lines I read in. Why is there a compiler discrepancy? When I hit debug and chose MS Visual Studio 2005 (I have a student's version but don't like it very much) the log stated that I had multiple access violations at 0xfffffffa. What does that mean? On a side note, is stack size compiler dependent or machine/OS dependent? Is that why my program crashes with Borland and not CodeWarrior? If you run out of stack space will you automatically start using the heap?

Share this post


Link to post
Share on other sites
I was having somewhat of the same problem earlier. My code also crashed when compiled with VC++, but not with MinGW. It turned out I was using delete on a pointer that had already been deleted. Chances are you aren't checking for possible errors along the way or you're doing something like I did that's known to cause errors.

As for your other questions, I can't help you there.

Share this post


Link to post
Share on other sites
I've got VC++ version 6 (full standard edition) and 2005 (free "express" edition) on my machine. E-mail the source to webmaster@t104.org and I'll see if I can help. Just send a short message and attach the .CPP and .H files - don't bother with the project file.

On another note, an access violation usually means that you're either doing something with a null pointer or reading / writing past the end of an array. Some compilers may behave differently for some of these things - as another poster mentioned, deleting an invalid address is one.

Share this post


Link to post
Share on other sites
Quote:
Original post by Alpha_ProgDes
Show da code!


It's like 400 lines long and I'm not sure where it's crashing since I can't step through with the Borland compiler.

Share this post


Link to post
Share on other sites
Quote:
Original post by AncientPC
Quote:
Original post by Alpha_ProgDes
Show da code!


It's like 400 lines long and I'm not sure where it's crashing since I can't step through with the Borland compiler.


We can't tell you what is the problem until we see the code.

As for compiler descrepency, it's actually pretty common. Different compilers sometimes treat certain things differently, thus why in one case one may result in a bug while the other would not.

Share this post


Link to post
Share on other sites
I can already guess exactly what is happening based on the error.

Codewarrior is initializing memory by clearing it to zero. This may be a normal behavoir, it may be because you have a debugging setting set (most likely the second). Borland is not wasting time in your code initializing memory to zero, either because it is in a release setting, or because it is not considered a useful debug setting (it does after all create odd debug/release differences).

This has likely resulted in one of two types of bugs.

One type is a pointer bug, where you have a pointer test (or a free operation, which does a pointer test to see if there is actually memory to free), and that is failing because there is a garbage value (it attempts to free memory that is not allocated, or assumes an object has been initilized because it is not null, when in fact it is just pointing to random memory).

The other type is that you are not initializing your variables to known value, resulting in unusual behavoir. One example might be an array index. With memory zeroed, it initially points to the first element in the array. When not, it can point to the 11 millionth element, which does not exist and causes an exception. There are many ways variables with unpredictable values could affect your code, ultimately leading it down a path leading to an access violation.

Share this post


Link to post
Share on other sites
Please, show the code, so that something can be learned. "over 400 lines" is not a problem; that's what [source][/source] tags are for.

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