Tuesday, June 1, 2010

Assertions

I splitted the runtime into multiple parts. This is the most boring part, just used for debugging.

/**
 *  COPYRIGHT 2010, M.C.A. Devillers
 *
 *  THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
 *  EXPRESSED OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
 *
 *  Two macros which handle debugging.
 */
#ifndef ASSERT_H
#define ASSERT_H
#include <stdlib.h>
#include <stdio.h>
#ifndef TRACE
#define TRACE \
    {fprintf(stdout, \
        "file %s: line %d: trace\n", \
            __FILE__, \
            __LINE__); \
    fflush(stdout);}
#endif
#ifndef ASSERT
#define ASSERT(b) \
    {if (!(b)) { \
        fprintf(stderr, \
            "file %s: line %d: assertion failed (%s)\n", \
                __FILE__, \
                __LINE__, \
                #b); \
        exit(1); \
        } \
    };
#endif
#ifndef DEBUG
#define DEBUG(b)    b
#endif
#endif // ASSERT_H

No comments:

Post a Comment