7073ea6ea297fa81ed4ebbfe87d2067484617490
[cparser] / adt / align.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20
21 /*
22  * Project:     libFIRM
23  * File name:   ir/adt/align.h
24  * Purpose:     macros for alignment.
25  * Author:      Markus Armbruster
26  * Modified by:
27  * Created:     1999 by getting from fiasco
28  * CVS-ID:      $Id$
29  * Copyright:   (c) 1995, 1996 Markus Armbruster
30  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
31  */
32 #ifndef _ALIGN_H
33 #define _ALIGN_H
34
35 #include <stddef.h>
36
37 /**
38  * @file align.h
39  */
40
41 /** A size handled efficiently by malloc(), at least 1K.  */
42 #define PREF_MALLOC_SIZE 2048
43
44
45 /** A wrapper around GNU C's __attribute__ */
46
47 /* According to the documentation, the attributes we are interested in
48    work with 2.5, but we encountered trouble before 2.7.  */
49 #if defined (__GNUC__) && __GNUC__ >= 2 && __GNUC_MINOR__ >= 7
50 # define HAVE_ATTRIBUTE 1
51 # define ATTRIBUTE(attrs) __attribute__ (attrs)
52 #else
53 # define ATTRIBUTE(attrs)
54 #endif
55
56
57 /* Alignment */
58
59 /** A type that has most constrained alignment.  */
60 typedef union {
61   long double d;
62   void *p;
63   long l;
64 } aligned_type ATTRIBUTE ((aligned));
65
66 /** Inquiring about the alignment of a type.  */
67 #ifdef __GNUC__
68 # define ALIGNOF(type) __alignof__ (type)
69 #else
70 # define ALIGNOF(type) offsetof (struct { char c; type d; }, d)
71 #endif
72
73 /** Maximal alignment required for any type.  */
74 #define MAX_ALIGN ALIGNOF (aligned_type)
75
76 #endif /* _ALIGN_H */