- add two more (void *) casts to should up MSVC const problems
[libfirm] / include / libfirm / adt / align.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       macros for alignment.
23  * @author      Markus Armbruster
24  * @version     $Id$
25  */
26 #ifndef FIRM_ADT_ALIGN_H
27 #define FIRM_ADT_ALIGN_H
28
29 #include <stddef.h>
30
31 /** A size handled efficiently by malloc(), at least 1K.  */
32 #define PREF_MALLOC_SIZE 2048
33
34
35 /** A wrapper around GNU C's __attribute__ */
36
37 /* According to the documentation, the attributes we are interested in
38    work with 2.5, but we encountered trouble before 2.7.  */
39 #if defined (__GNUC__) && __GNUC__ >= 2 && __GNUC_MINOR__ >= 7
40 # define HAVE_ATTRIBUTE 1
41 # define ATTRIBUTE(attrs) __attribute__ (attrs)
42 #else
43 # define ATTRIBUTE(attrs)
44 #endif
45
46
47 /* Alignment */
48
49 /** A type that has most constrained alignment.  */
50 typedef union {
51   long double d;
52   void *p;
53   long l;
54 } aligned_type ATTRIBUTE ((aligned));
55
56 /** Inquiring about the alignment of a type.  */
57 #ifdef __GNUC__
58 # define ALIGNOF(type) __alignof__ (type)
59 #else
60 # define ALIGNOF(type) offsetof (struct { char c; type d; }, d)
61 #endif
62
63 /** Maximal alignment required for any type.  */
64 #define MAX_ALIGN ALIGNOF (aligned_type)
65
66 #endif