summaryrefslogtreecommitdiff
path: root/mcon/U/intsize.U
blob: 264f6b6b890829ccb1c837b25c84dd96538f4bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
?RCS: $Id: intsize.U 167 2013-05-08 17:58:00Z rmanfredi $
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, 2012 Raphael Manfredi
?RCS: 
?RCS: You may redistribute only under the terms of the Artistic License,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic License; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
?MAKE:intsize longsize shortsize: Assert Myread cat rm +cc +ccflags echo n c
?MAKE:	-pick add $@ %<
?S:intsize:
?S:	This variable contains the value of the INTSIZE symbol, which
?S:	indicates to the C program how many bytes there are in an int.
?S:.
?S:longsize:
?S:	This variable contains the value of the LONGSIZE symbol, which
?S:	indicates to the C program how many bytes there are in a long.
?S:.
?S:shortsize:
?S:	This variable contains the value of the SHORTSIZE symbol which
?S:	indicates to the C program how many bytes there are in a short.
?S:.
?C:INTSIZE:
?C:	This symbol contains the value of sizeof(int) so that the C
?C:	preprocessor can make decisions based on it.
?C:.
?C:LONGSIZE:
?C:	This symbol contains the value of sizeof(long) so that the C
?C:	preprocessor can make decisions based on it.
?C:.
?C:SHORTSIZE:
?C:	This symbol contains the value of sizeof(short) so that the C
?C:	preprocessor can make decisions based on it.
?C:.
?H:#define INTSIZE $intsize
?H:#define LONGSIZE $longsize
?H:#define SHORTSIZE $shortsize
?H:.
?T:types t size var
?LINT: set shortsize intsize longsize
: check for lengths of integral types
echo " "
types=''
@if SHORTSIZE || shortsize
types="$types short"
@end
@if INTSIZE || intsize
types="$types int"
@end
@if LONGSIZE || longsize
types="$types long"
@end
for t in $types; do
	$echo $n "Checking to see how big your ${t}s are...$c" >&4
	for size in 2 4 8 16 error; do
		$cat >try.c <<EOCP
#include "static_assert.h"
$t foo;
int main()
{
	STATIC_ASSERT($size == sizeof(foo));
	return 0;
}
EOCP
		if $cc -c $ccflags try.c >/dev/null 2>&1; then break; fi
	done
	var=${t}size
	case "$size" in
	error)
		echo " cannot compute it." >&4
		case $t in
		short) dflt=2;;
		int) dflt=4;;
		long) dflt=4;;
		esac
		rp="What is the size of the \"$t\" type (in bytes)?"
		. ./myread
		eval $var="$ans"
		;;
	*)
		echo " $size bytes." >&4
		eval $var=$size
		;;
	esac
done
$rm -f try.*