aborting execution

P

pauldepstein

Is there any standard c++ command for halting execution? The nearest
equivalent I can find is assert(false); However this only works in
debug mode.

I'm trying to examine the execution flow of my program but an issue is
that debug mode is enormously slow, so setting breakpoints is
enormously slow. For speed, I want to do as much as possible in
release mode.

It occurs to me that, if I knew a c++ command for halting execution, I
could see which line was being executed while in release mode.

Paul Epstein
 
P

pauldepstein


Thanks.

I was using assert statements before I decided debug mode was just too
slow and to try other approaches. However, having tried both abort()
and assert(false) on the vc++ compiler, I've noticed that assert is
much more helpful -- in particular it gives the precise linenumber of
the crash.

I know it's probably a compiler-dependent question but is there a way
of getting a line number with abort().

Paul Epstein
 
A

anon

Thanks.

I was using assert statements before I decided debug mode was just too
slow and to try other approaches. However, having tried both abort()
and assert(false) on the vc++ compiler, I've noticed that assert is
much more helpful -- in particular it gives the precise linenumber of
the crash.

I know it's probably a compiler-dependent question but is there a way
of getting a line number with abort().


This is how I check errors in my opengl programs:

void checkOpenGlError( const unsigned int lineNo )
{
const GLenum err ( glGetError( ) );
if ( GL_NO_ERROR != err )
{
std::cerr << "OpenGl error : " << lineNo << " "
<< gluErrorString( err ) << std::endl;
exit( EXIT_FAILURE );
}
}

Then when I want to check the error, I call like this:
checkOpenGlError( __LINE__ );

Therefore, instead of exiting with abort(), or assert(false), you can
implement something similar.
 
I

Ian Collins

Thanks.

I was using assert statements before I decided debug mode was just too
slow and to try other approaches. However, having tried both abort()
and assert(false) on the vc++ compiler, I've noticed that assert is
much more helpful -- in particular it gives the precise linenumber of
the crash.

I know it's probably a compiler-dependent question but is there a way
of getting a line number with abort().
Call it with assert? Why not just enable asserts in you application?
Asserts and optimisation are orthogonal, so you can have one without the
other, just don't define NDEBUG.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top