Die, DOS, die!

I hatedislike programming on the school computers using Windows, the DJGPP compiler and no decent terminal. One of the most annoying problems is that you can only see the last ~25 lines of your program’s output. gdb doesn’t catch assertion failures for some reason, so you’re left dealing with your bugs with bare hands… talk about dirty work!

This reminded me of the old “DOS” way of waiting for a key press every now and then. Here’s one of my latest quick-and-dirty-and-not-properly-tested tricks:

#define assert(a) if(!(a)) { printf(“MyAssert(%s) failed\n”, #a); \
freopen(“con“, “r”, stdin); \
getchar(); \
abort(); }

If stdin is freopen‘d to some file, the getchar() will not accomplish its job of waiting for a keyboard stroke. That’s why the freopen is there. (Remember how you could crash Win9x by running ‘c:\con\con‘?)

So now, instead of crashing with a useless stack trace and no clue to which assert failed in only 25 lines, it gracefully shows:

MyAssert(the::world.isFlat()) failed

waits for you to read the message and press Enter, and then aborts. Problem solved 8-)

2 Responses to Die, DOS, die!

  1. What about logging to files?

  2. Constantin says:

    There would be enough problems then, too, like having to flush the stream each time you write to it. Redirection (piping) may “forget” the last few lines if the program crashes (last time I checked).

    It seems too much of a hassle since in a few hours I’m back to my home PC with Linux, but I would do it for a larger scale program ;)

%d bloggers like this: