This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Metaconfig units changes for #9560, plus regen Glossary.patch.
[metaconfig.git] / U / perl / d_u32align.U
CommitLineData
d85168a5
JH
1?RCS: $Id$
2?RCS:
3?RCS: Copyright (c) 2001, Jarkko Hietaniemi
4?RCS:
5?RCS: You may redistribute only under the terms of the Artistic Licence,
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
8?RCS: that same Artistic Licence; a copy of which may be found at the root
9?RCS: of the source tree for dist 3.0.
10?RCS:
11?MAKE:d_u32align: Compile cat rm Oldconfig \
12 byteorder u32type Myread Setvar
13?MAKE: -pick add $@ %<
14?S:d_u32align:
15?S: This variable tells whether you must access character data
16?S: through U32-aligned pointers.
17?S:.
18?C:U32_ALIGNMENT_REQUIRED:
19?C: This symbol, if defined, indicates that you must access
20?C: character data through U32-aligned pointers.
21?C:.
22?H:#$d_u32align U32_ALIGNMENT_REQUIRED /**/
23?H:.
24?F:!try
25$cat <<EOM
26
27Checking to see whether you can access character data unalignedly...
28EOM
29$cat >try.c <<EOCP
30#include <stdio.h>
31#define U32 $u32type
32#define BYTEORDER $byteorder
33int main() {
34#if BYTEORDER == 0x1234 || BYTEORDER == 0x4321
35 U8 buf[] = "\0\0\0\1\0\0\0\0";
36 U32 *up;
37 int i;
38
39 if (sizeof(U32) != 4) {
40 printf("sizeof(U32) is not 4, but %d\n", sizeof(U32));
41 exit(1);
42 }
43
44 fflush(stdout);
45
46 for (i = 0; i < 4; i++) {
47 up = (U32*)(buf + i);
48 if (! ((*up == 1 << (8*i)) || /* big-endian */
49 (*up == 1 << (8*(3-i))) /* little-endian */
50 )
51 )
52 {
53 printf("read failed (%x)\n", *up);
54 exit(2);
55 }
56 }
57
58 /* write test */
59 for (i = 0; i < 4; i++) {
60 up = (U32*)(buf + i);
61 *up = 0xBeef;
62 if (*up != 0xBeef) {
63 printf("write failed (%x)\n", *up);
64 exit(3);
65 }
66 }
67
68 exit(0);
69#else
70 printf("1\n");
71 exit(1);
72#endif
73 return 0;
74}
75EOCP
76set try
77if eval $compile_ok; then
78 echo "(This test may dump core.)" >&4
79 ./try >&2 >/dev/null
80 case "$?" in
81 0) cat >&4 <<EOM
82You can access character data pretty unalignedly.
83EOM
84 d_u32align="$undef"
85 ;;
86 *) cat >&4 <<EOM
87It seems that you must access character data in an aligned manner.
88EOM
89 d_u32align="$define"
90 ;;
91 esac
92 $rm -f core core.try.* try.core
93else
94 rp='Can you access character data at unaligned addresses?'
95 dflt='n'
96 . ./myread
97 case "$ans" in
98 [yY]*) d_u32align="$undef" ;;
99 *) d_u32align="$define" ;;
100 esac
101fi
102