make firm (mostly) -Wmissing-prototypes clean
[libfirm] / ir / libcore / lc_defines.h
1 /*
2   libcore: library for basic data structures and algorithms.
3   Copyright (C) 2005  IPD Goos, Universit"at Karlsruhe, Germany
4
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20
21 /**
22  * Some common defines.
23  * @author Sebastian Hack
24  * @date 22.12.2004
25  */
26
27 #ifndef _LIBCORE_DEFINES_H
28 #define _LIBCORE_DEFINES_H
29
30 #define LC_ARRSIZE(x)             (sizeof(x) / sizeof(x[0]))
31
32 #define LC_MIN(x,y)                               ((x) < (y) ? (x) : (y))
33 #define LC_MAX(x,y)                               ((x) > (y) ? (x) : (y))
34
35 /** define a readable fourcc code */
36 #define LC_FOURCC(a,b,c,d)        ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
37 #define LC_FOURCC_STR(str)                        LC_FOURCC(str[0], str[1], str[2], str[3])
38
39 #define LC_OFFSETOF(type,memb)    ((char *) &((type *) 0)->memb - (char *) 0)
40
41 #ifdef __GNUC__
42 #define LC_ALIGNOF(type)                                  __alignof__(type)
43 #else
44 #define LC_ALIGNOF(type)                                  LC_OFFSETOF(struct { char c; type d; }, d)
45 #endif
46
47 #define LC_PTR2INT(x) (((char *)(x)) - (char *)0)
48 #define LC_INT2PTR(x) (((char *)(x)) + (char *)0)
49
50 #endif