root/assert.h

Revision 106, 2.1 kB (checked in by ng, 5 years ago)

mise a jour licence

Line 
1 /***************************************************************************
2  *   This file is part of the 'gemmes' project                             *
3  *                                                                         *
4  *                                                                         *
5  *   Copyright (C) 2007 by                                                 *
6  *         GARCH Soufiane                                                  *
7  *         GUILLAUME Nicolas <ng@ngsoft-fr.com>                            *
8  *                                                                         *
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; version 2 of the License only.          *
13  *   See the COPYING file.                                                 *
14  ***************************************************************************/
15
16
17 #ifndef ASSERT_H
18 #define ASSERT_H
19
20 #include <stdio.h>
21 #include <stdlib.h>
22
23
24
25
26 /** check that cond is true, str is displayed if it fails */
27 #define c_assert2(cond, str) __assert((cond), __LINE__, __FILE__, (str), #cond)
28
29 /** check that cond is true, "assertion failed" is displayed if it failed */
30 #define c_assert(cond) c_assert2((cond), "assertion failed")
31
32
33 /** warm by showing str if cond is not true */
34 #define c_warning2(cond, str) __warning((cond), __LINE__, __FILE__, (str), #cond)
35
36 /** warm by showing "warning" if cond is not true */
37 #define c_warning(cond) c_warning2((cond), "warning")
38
39
40
41
42
43
44
45
46
47
48 #ifndef DISABLE_ASSERT
49
50
51 #define __assert(cond, line, file, str, cond_str) \
52           { if(!cond) { fprintf(stderr, "assertion error on `" cond_str "' in " file  " at line %d: %s\n", line, str); abort(); } }
53 #define __warning(cond, line, file, str, cond_str) \
54           { if(!cond) { fprintf(stderr, "warning on `" cond_str "' in " file  " at line %d: %s\n", line, str) ; } }
55
56 #else
57
58 #define __assert(cond, line, file, str, cond_str)
59 #define __warning(cond, line, file, str, cond_str)
60
61 #endif
62
63
64 #endif
Note: See TracBrowser for help on using the browser.