Question:
in c++ program while running a program i faces an error.?
Akash
2011-07-17 04:57:48 UTC
error detail is as follows.
The NTVDM CPU has encountered an illegal instruction.
CS:0f18 IP:00ef OP:63 6f 6e 64 2e Choose 'Close' to terminate the application.

Even after going through the whole program i could not find wrong instruction.
please tell me the solution.
Four answers:
husoski
2011-07-17 06:20:32 UTC
Welcome to debugging! This sort of crash in C and C++ programs is usually due to a pointer or array handling problem.



You are using a DOS-based product (NTVDM is the Windows' "Virtual DOS Machine", originally developed for WIndows NT...hence "NTVDM"), and I'd guess it's Turbo C++ since lots of places seem to be using that as a "free teaching tool". If so, see if you can find out how to use TD: the Turbo Debugger. If nothing else, that will allow you to trace up to the point of the error...and then maybe you can work out what's gone wrong from the tail end of the trace.



The time-honored way of doing this without a debugger is to embed extra tests and diagnostic printf() calls to create your own trace. Just simple printf() statements like "I got here!\n" will show you the last few "checkpoints" before the program totally failed.



The C/C++ assert macro (#include for C and old versions of C++, or in Standard C++) can be used to place assumption checks that are silent unless something is wrong. An "assert(expression);" statement says that the "expression" must be true for correct program execution. The library is usually set up to generate code to test that assertion when compiled in debug mode, or no code when compiled for release (where a #define NDEBUG is done either in a header file or on the command line.) Something as simple as "unneccessary" as:



asssert((source != NULL) && strlen(source)>=0 && strlen(source)


...before doing a strcpy(dest, source), can detect a memory clobber before it happens.



Also, turn on all warnings in the compiler. Sometimes those will point out things that, while technically legal, may indicate a programming error. Or technically illegal, but not normally checked by the compiler, like forgetting to initialize a variable.



One great way to find program errors is to explain your program and "prove that there are no errors" to a patient friend. Friends can be a rich source of annoyingly pertinent questions.
Ratchetr
2011-07-17 06:23:16 UTC
The values 63 6f 6e 64 2e are the 'code' it is trying to execute.

Those look suspiciously like ASCII characters. They translate to: 'cond.'



That usually means you have a memory overwrite in a function somewhere, a write that is going off the end of an array and corrupting other data on the stack. One thing that is on the stack is the return address. If that gets overwritten, then when your function returns, it will return to the wrong place.



For example:

void f()

{

  char ary[2];

  ary[8] = 0;

}



ary[8] isn't part of the array, but C++ will still go ahead and write a 0. Since ary is a stack variable, there is a good chance that could change the return address. So when f() returns, there is no telling where it will go or what it will do. But executing an illegal instruction is certainly 1 possibility.



Look for code that's doing something like that.
?
2016-12-08 10:43:06 UTC
hi, engaged on nonetheless quick C. you're sweet baby . once you turns into grown up. Now each thing shifting to sixty 4 bit computing . you're engaged on 16 bit compiler. use another compiler.
anonymous
2011-07-17 12:08:45 UTC
just the pointer problem..study the concept of pointer once again properly and do..pointers r very dangerous sometime


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...