Commit | Line | Data |
---|---|---|
d8875586 MBT |
1 | ?RCS: $Id$ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi | |
4 | ?RCS: | |
c6667804 | 5 | ?RCS: You may redistribute only under the terms of the Artistic License, |
d8875586 MBT |
6 | ?RCS: as specified in the README file that comes with the distribution. |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
c6667804 | 8 | ?RCS: that same Artistic License; a copy of which may be found at the root |
d8875586 MBT |
9 | ?RCS: of the source tree for dist 4.0. |
10 | ?RCS: | |
11 | ?RCS: $Log: alignbytes.U,v $ | |
12 | ?RCS: Revision 3.0.1.2 1994/10/29 16:02:28 ram | |
13 | ?RCS: patch36: added ?F: line for metalint file checking | |
14 | ?RCS: | |
15 | ?RCS: Revision 3.0.1.1 1994/05/06 14:25:20 ram | |
16 | ?RCS: patch23: avoid ALIGNBYTES, since it conflicts on NetBSD | |
17 | ?RCS: | |
18 | ?RCS: Revision 3.0 1993/08/18 12:05:23 ram | |
19 | ?RCS: Baseline for dist 3.0 netwide release. | |
20 | ?RCS: | |
21 | ?MAKE:alignbytes: Assert Myread Trylink cat i_inttypes i_limits i_math | |
22 | ?MAKE: -pick add $@ %< | |
23 | ?S:alignbytes: | |
24 | ?S: This variable holds the number of bytes required to align an | |
25 | ?S: arbitrary standard type. Usual values are 2, 4 and 8. | |
26 | ?S:. | |
27 | ?X: This used to be called ALIGNBYTES, but that conflicts with | |
28 | ?X: <machines/param.h> in NetBSD. | |
29 | ?C:MEM_ALIGNBYTES (ALIGNBYTES): | |
30 | ?C: This symbol contains the number of bytes required to align a | |
31 | ?C: double. Usual values are 2, 4 and 8. | |
32 | ?C:. | |
33 | ?H:#define MEM_ALIGNBYTES $alignbytes /**/ | |
34 | ?H:. | |
35 | ?T:alignment result | |
36 | : check for alignment requirements | |
37 | echo " " | |
38 | case "$alignbytes" in | |
39 | '') | |
40 | echo "Checking alignment constraints..." >&4 | |
41 | ||
42 | for alignment in 8 4 2 1 16 32 error | |
43 | do | |
44 | $cat >try.c <<EOCP | |
45 | #$i_inttypes I_INTTYPES | |
46 | #ifdef I_INTTYPES | |
47 | #include <inttypes.h> | |
48 | #endif | |
49 | #$i_limits I_LIMITS | |
50 | #ifdef I_LIMITS | |
51 | #include <limits.h> | |
52 | #endif | |
53 | #$i_math I_MATH | |
54 | #ifdef I_MATH | |
55 | #include <math.h> | |
56 | #endif | |
57 | ||
58 | union u { | |
59 | void *void_ptr; | |
60 | void (*func_ptr)(void); | |
61 | char c; | |
62 | short s; | |
63 | int i; | |
64 | long l; | |
65 | float f; | |
66 | double d; | |
67 | #ifdef LLONG_MAX | |
68 | long long ll; | |
69 | #else | |
70 | #warning "LLONG_MAX undefined" | |
71 | #endif | |
72 | #if defined(HUGE_VALL) | |
73 | long double ld; | |
74 | #else | |
75 | #warning "HUGE_VALL undefined" | |
76 | #endif | |
77 | #ifdef UINT32_MAX | |
78 | uint32_t u32; | |
79 | #else | |
80 | #warning "UINT32_MAX undefined" | |
81 | #endif | |
82 | #ifdef UINT16_MAX | |
83 | uint16_t u16; | |
84 | #else | |
85 | #warning "UINT32_MAX undefined" | |
86 | #endif | |
87 | #ifdef UINT64_MAX | |
88 | uint64_t u64; | |
89 | #else | |
90 | #warning "UINT64_MAX undefined" | |
91 | #endif | |
92 | #ifdef UINTMAX_MAX | |
93 | uintmax_t m; | |
94 | #else | |
95 | #warning "UINTMAX_MAX undefined" | |
96 | #endif | |
97 | #ifdef UINTPTR_MAX | |
98 | uintptr_t up; | |
99 | #else | |
100 | #warning "UINTPTR_MAX undefined" | |
101 | #endif | |
102 | }; | |
103 | ||
104 | struct s { | |
105 | char a; | |
106 | union u b; | |
107 | }; | |
108 | ||
109 | #include "static_assert.h" | |
110 | ||
111 | int | |
112 | main(void) | |
113 | { | |
114 | STATIC_ASSERT($alignment == ((sizeof (struct s) - (sizeof (union u))))); | |
115 | return 0; | |
116 | } | |
117 | EOCP | |
118 | ||
119 | result='' | |
120 | set result | |
121 | eval $trylink | |
122 | case "$result" in | |
123 | "$define") break;; | |
124 | esac | |
125 | done | |
126 | ||
127 | case "$alignment" in | |
128 | error) dflt='8' | |
129 | echo "(I can't seem to compile the test program...)" >&4 | |
130 | ;; | |
131 | *) dflt=$alignment | |
132 | ;; | |
133 | esac | |
134 | ;; | |
135 | *) dflt="$alignbytes" | |
136 | ;; | |
137 | esac | |
138 | rp="What is the maximum alignment in bytes required for a standard type?" | |
139 | . ./myread | |
140 | alignbytes="$ans" | |
141 |