-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathlimits_h.c
58 lines (43 loc) · 1.4 KB
/
limits_h.c
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
/*
# limits.h
Gives the maximum and minimum values that fit into base integer types
in the current architecture.
*/
#include "common.h"
int main(void) {
{
/*
# CHAR_BIT
Numbers of bits in a char == number of bits in a C byte (not necessarily 8!)
POSIX fixes it to 8 TODO reference.
`sizeof` returns results in multiples of it.
*/
printf("CHAR_BIT = %d\n", CHAR_BIT);
/* Guaranteed. */
assert(CHAR_BIT >= 8);
/*
# CHAR_MAX
Remember that signed char is different from char:
it can be either signed or unsigned.
*/
printf("CHAR_MAX = %d\n", CHAR_MAX);
/*
# SCHAR_MAX
TODO Not redundant with by CHAR_BIT? Maybe not: CHAR_BIT is about memory size,
but it could have some dead bits around for some reason, ans CHAR_MAX could be smaller.
*/
printf("SCHAR_MIN = %d\n", SCHAR_MIN);
printf("SCHAR_MAX = %d\n", SCHAR_MAX);
}
/* # INT_MAX */
printf("INT_MAX = %d\n", INT_MAX);
printf("INT_MIN = %d\n", INT_MIN);
printf("LONG_MAX = %ld\n", LONG_MAX);
printf("LLONG_MIN = %lld\n", LLONG_MIN);
/*
Unsigned versions are prefixed by `U`.
There is no MIN macro for unsigned versions since it is necessarily `0`.
*/
printf("UINT_MAX = %u\n", UINT_MAX);
return EXIT_SUCCESS;
}