×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Turbo C++: strange behaviour of my code

Turbo C++: strange behaviour of my code

Turbo C++: strange behaviour of my code

(OP)
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.

RE: Turbo C++: strange behaviour of my code

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...

RE: Turbo C++: strange behaviour of my code

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close