Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turbo C++: strange behaviour of my code

Status
Not open for further replies.

stefanhubert

Programmer
Nov 1, 2001
2
US
PROCESSOR: 133 MHz
OS: MS DOS 6.22
COMPILER: Borland Turbo C++ 3.0

Hi there,

This is the first time I use the Borland Turbo C++ environment.
This is the first I code a more complex application C++.
I make use of some classes.

My code behaves really strange. Dependent on the sequence and complexity of the code I test my classes/modules with, ONE OF the following behaviours occures:

-On a certain position I call the new operator to allocate an array of characters. Executing this instruction, the content of an other string becomes overwritten, that is not even involved in that statement (line of code). (This does not happen every time, I call the function containing that certain statement, but each time, i debug my program, at the same position in my program's progress.)

-I call strlen(..) on a certain position in my program. That courses the string's content to become overwirtten. Like above, this does not occur every time I call strlen() but each time at the same state of progress of my program.

-Presumabely the function call stack becomes damaged. Some of the bottom entries ( Showed in the Debug/Call Stack.. -dialog )disappear at a certain line of code.

I currently imply that I made a mistake, and have to find it. Other possibilities are an error of the copmiler or others....

In case this sounds familiar to somebody: I am graceful to every kinds of clues, hints!!! since I already spent a couple of days to find this error, and the customer and my boss urge to finish this project, not to talk about of my own will to get that out of my way.


thanks a lot in advance,

Stefan Hubert

P.S.
Since my source code is still quite complex (a couple of classes are involved) I do not include source code here, but of course I could send it, in case sombody wants to have a look at it, what was certainly necessary in order to try to find the reason.
 
Strange behaviour like that usually occurs when you're writing on a piece of memory that isn't reserved. So I'd say that your new function did not execute or, you forgot to put an "\0" on the end of your array (if it has to serve as a string that is).
Can you show how you declare your array ? The Muppeteer.



Don't eat yellow snow...
 
Hi,

Thank you for your answer.

A couple of days ago i finally found the mistake caused these errors.
I passed (by mistake) a reference to a variable was residing on the stack out of a certain function.
Later, this variable became overwritten by instructions the compiler inserts automatically to manipulate the function stack each time I call a function.
The other way around, when I wrote content of this variable, I screwed up the function stack structure, managed by the compiler itself.

take care,

Stefan Hubert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top