util.h 1.41 KB
Newer Older
1
/*
Michael Beck's avatar
Michael Beck committed
2
 * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3
4
5
6
7
8
9
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
Sebastian Hack's avatar
Sebastian Hack committed
10
 *
11
12
13
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
Sebastian Hack's avatar
Sebastian Hack committed
14
 *
15
16
17
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
Sebastian Hack's avatar
Sebastian Hack committed
18
19
 */

20
21
22
23
/**
 * @file
 * @date   31.05.2005
 * @author Sebastian Hack
24
 * @brief  Some utility macros.
25
 */
26
27
#ifndef FIRM_ADT_UTIL_H
#define FIRM_ADT_UTIL_H
Sebastian Hack's avatar
Sebastian Hack committed
28

29
#include <stddef.h>
Sebastian Hack's avatar
Sebastian Hack committed
30
31
32
33
34
35
36
37

/**
 * Make pointer to the struct from a pointer to a member of that struct.
 * @param ptr     The pointer to the member.
 * @param type    The type of the struct.
 * @param member  The name of the member.
 * @return        A pointer to the struct member is in.
 */
38
39
40
41
42
43
44
45
46
47
#define firm_container_of(ptr, type, member) \
	((type *) ((char *) (ptr) - offsetof(type, member)))

/**
 * Returns size of a static array. Warning: This returns invalid values for
 * dynamically allocated arrays.
 *
 * @param a    static array
 */
#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
Sebastian Hack's avatar
Sebastian Hack committed
48

49
#endif