|
|
1 | /* |
|
|
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
|
|
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
|
|
5 | * |
|
|
6 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
|
|
7 | * under the terms of the GNU General Public License as published by the Free |
|
|
8 | * Software Foundation; either version 2 of the License, or (at your option) |
|
|
9 | * any later version. |
|
|
10 | * |
|
|
11 | * This program is distributed in the hope that it will be useful, but |
|
|
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
|
13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
|
14 | * for more details. |
|
|
15 | * |
|
|
16 | * You should have received a copy of the GNU General Public License along |
|
|
17 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
|
|
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
19 | * |
|
|
20 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
|
|
21 | */ |
|
|
22 | |
1 | #ifndef UTIL_H__ |
23 | #ifndef UTIL_H__ |
2 | #define UTIL_H__ |
24 | #define UTIL_H__ |
3 | |
25 | |
4 | //#define PREFER_MALLOC |
26 | //#define PREFER_MALLOC |
5 | |
27 | |
… | |
… | |
11 | # define is_constant(c) 0 |
33 | # define is_constant(c) 0 |
12 | # define expect(expr,value) (expr) |
34 | # define expect(expr,value) (expr) |
13 | # define prefetch(addr,rw,locality) |
35 | # define prefetch(addr,rw,locality) |
14 | #endif |
36 | #endif |
15 | |
37 | |
|
|
38 | #if __GNUC__ < 4 || (__GNUC__ == 4 || __GNUC_MINOR__ < 4) |
|
|
39 | # define decltype(x) typeof(x) |
|
|
40 | #endif |
|
|
41 | |
16 | // put into ifs if you are very sure that the expression |
42 | // put into ifs if you are very sure that the expression |
17 | // is mostly true or mosty false. note that these return |
43 | // is mostly true or mosty false. note that these return |
18 | // booleans, not the expression. |
44 | // booleans, not the expression. |
19 | #define expect_false(expr) expect ((expr) != 0, 0) |
45 | #define expect_false(expr) expect ((expr) != 0, 0) |
20 | #define expect_true(expr) expect ((expr) != 0, 1) |
46 | #define expect_true(expr) expect ((expr) != 0, 1) |
… | |
… | |
28 | |
54 | |
29 | #include <shstr.h> |
55 | #include <shstr.h> |
30 | #include <traits.h> |
56 | #include <traits.h> |
31 | |
57 | |
32 | // use a gcc extension for auto declarations until ISO C++ sanctifies them |
58 | // use a gcc extension for auto declarations until ISO C++ sanctifies them |
33 | #define auto(var,expr) typeof(expr) var = (expr) |
59 | #define auto(var,expr) decltype(expr) var = (expr) |
34 | |
60 | |
35 | // very ugly macro that basicaly declares and initialises a variable |
61 | // very ugly macro that basicaly declares and initialises a variable |
36 | // that is in scope for the next statement only |
62 | // that is in scope for the next statement only |
37 | // works only for stuff that can be assigned 0 and converts to false |
63 | // works only for stuff that can be assigned 0 and converts to false |
38 | // (note: works great for pointers) |
64 | // (note: works great for pointers) |