Some things to consider before even asking about runtime errors

So your program crashes and you are looking for help. Before that, make sure to consider the following points in order to provide the necessary information.
In the best case, you'll resolve the problem on your own.


Make sure that your program builds correctly,
We are not considering compiler/linker errors here. As a tip, if when your are building the program you receive a message that says `error' then you've got a build error.
Also, make sure that your code does follows the standard (c++98, c++11)
Compile with warnings
man gcc:Warnings are diagnostic messages that report constructions that are not inherently erroneous but that are risky or suggest there may have been an error.

By instance, uninitialized variables.

<nolyc>: -Wall is only -Wsome; it leaves out many warnings. To really get a lot of warnings, you should use '-Wall -Wextra -std=c++98 -pedantic' or '-Wall -Wextra -std=c++11 -pedantic'
(consult your compiler manual)

Of course, the idea is for you to read those warnings and analyze the code they refer to
Figure out where it crashes
So you run your code and it crashes. Great, consider yourself lucky.
Now, to figure out where it happens, you simply need to run your program through a debugger. When your program crashes it would point to the exact line that is causing it.
Also, take a look at the call stack (perform a backtrace) so you'll know how did it reach that point.

While you are at it, you may want to take a look at the state of the variables, in order to find abnormalities.

You'll need to compile your program with debugging information, `-g' for gcc.
Asking
So you couldn't figure out by your own, no problem.
Follow the guidelines about `how to ask'

Adding to those, include all that is needed to run your program properly, like an example input.
Also, try to reproduce the error in a simpler program.

Should be unnecessary to remark this, but indent your code properly and use meaningful names
Topic archived. No new replies allowed.