summaryrefslogtreecommitdiffstats
path: root/macro.h
blob: 368555deab7e3e529bfcbc3db92aa098ced04f59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef foomacrohfoo
#define foomacrohfoo

#include <stdio.h>
#include <assert.h>

#ifdef __GNUC__
#define PRETTY_FUNCTION __PRETTY_FUNCTION__
#else
#define PRETTY_FUNCTION ""
#endif

#define sa_return_if_fail(expr) \
    do { \
        if (!(expr)) { \
             fprintf(stderr, "%s: Assertion <%s> failed.\n", PRETTY_FUNCTION, #expr ); \
            return; \
        } \
    } while(0)

#define sa_return_val_if_fail(expr, val) \
    do { \
        if (!(expr)) { \
            fprintf(stderr, "%s: Assertion <%s> failed.\n", PRETTY_FUNCTION, #expr ); \
            return (val); \
        } \
    } while(0)

#define sa_assert assert

#define sa_assert_not_reached() sa_assert(!"Should not be reached.")

#define elementsof(x) (sizeof(x)/sizeof((x)[0]))

#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif

#endif