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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compile issue

Status
Not open for further replies.

maswien

Technical User
Sep 24, 2003
1,286
CA

I'm not a c++ guy, but we have some code was written by c++ and used to be working when it compiled on visual studio 6.0, after we upgraded to visual studio 7, the code compiles ok, but when run the executables, we got error like "unexpected error", anything I need to do on upgrading the visual studio?


Thanks
 
> anything I need to do on upgrading the visual studio?
Fix the bugs which were being hidden by your previous compiler.

Now that you're using a new compiler, some of the various random mistakes which went unnoticed are now bugs (other more obscure bugs will of course remain).

Trivial example
Code:
int main ( ) {
    int *pointer;   // an uninitialised pointer
    *pointer = 0;   // dereference uninitialised pointer
}
Now obviously writing 0 into some random memory location is a bad thing, but whether it actually kills your program with "unexpected error" is purely down to luck. Changing your compiler (or even just changing from debug to release builds) shuffles the deck.

We quite often see "my code works in debug and not in release" type problems and it all boils down to the same thing - there are still bugs in the code.

The original author stopped looking for bugs when the program ran successfully, not when it was in fact bug free.

--
 

I compiled the code in ebug mode, then run it, I got following message:

Debug Assertion Failed!

Program: c:\prg\transform.exe
File:dbgheap.c
line:1132

Expression: _CrtIsValidHeapPointer(pUserData)

...


can anybody tell me what these meaage mean?

Thanks a lot
 
It means you found a bug in your code.

Essentially, somewhere, the code does this.
Code:
char *s = new char[10];
strcpy( s, "this doesn't fit in 10 chars" );
It may or may not be a string, but its a pretty sure bet that something which has allocated some memory has used more than was originally requested.

This is a very bad thing - because that memory which has been overwritten could be being used for something else.
Part of the run-time system has detected that memory corruption has occurred, and has therefore stopped your program before any more damage can occur.

--
 

Thanks Salem,

Is there any way I can locate the line of problematic code?
Since we don't use visual studio to compile the code, How can I debug it without visual studio IDE?
 
> Since we don't use visual studio to compile the code, How can I debug it without visual studio IDE?
I'm confused - this seems to contradict your original post.

> Is there any way I can locate the line of problematic code?
Well you could just look at the memory which has been corrupted, and figure out where in the code that came from. This is easy to do for example if the memory contains say text strings which have been read from a file.

There are a number of tools (some free, some commercial) which can help narrow the search.

--
 

Sorry for the confuse,

I meant we installed visual stidio 6.0 as the compiler, we use command line instead of using the IDE to compile the code.

How can I look at a memory that has been corrupted?

Thanks
 
Why not just use the IDE? It was made to help you debug things...
 

Using 6.0 compiler, following instructor function is fine and runs OK,

TSqlExecutor(int argc, char** argv, const TCLParams &clparams);

But compiled with MSVC 7.0, it gives 'expected error'. If change it to :

TSqlExecutor(int argc, char** argv, const TCLParams clparams);

Then it runs OK. TCLParams is defined as:

TCLParams(TCLParam* first, TCLParam* last) : vector<TCLParam>(first, last) {};

TCLParam is a class.


Can you tell me why?

Thanks

 
I don't think there is enough information to figure it out with just that, but my guess is that VC++ 7.0 is finding errors in your code not conforming to the C++ standard that it wasn't finding in 6.0.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top