The Allegro Wiki is migrating to github at https://github.com/liballeg/allegro_wiki/wiki

Debug snippet

From Allegro Wiki
Jump to: navigation, search

A collection of simple macros useful for debugging.

By James Lawder Andrews aka Zaphos, except to the extent that it isn't because it's on a publicly editable website :)

debug.h

<highlightSyntax language="cpp">/** Helper debug macros allows easy DEBUGOUT to file when DEBUG is defined

  • /
  1. ifndef _DEBUG_H_
  2. define _DEBUG_H_
  1. define DEBUG
  1. ifdef DEBUG
  2. include <fstream>
  3. define DEBUGOUT(blah) debug << "(" << __FILE__ << ":" << __LINE__ << ") " << blah << std::endl << std::flush;
  4. define DODEBUG(blah) blah
  5. else
  6. define DEBUGOUT(blah)
  7. define DODEBUG(blah)
  8. endif
  1. ifdef DEBUG

extern std::ofstream debug;

  1. endif
  1. endif
</highlightSyntax>

debug.cpp

<highlightSyntax language="cpp">#include "debug.h"

  1. ifdef DEBUG

std::ofstream debug("debug.txt");

  1. endif
</highlightSyntax>