1 /* typecard - prints basic C types and their sizes.
2  * Used for the eschalot development and cross-platform testing. */
3 
4 /*
5  * Copyright (c) 2013 Unperson Hiro <blacksunhq56imku.onion>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include <ctype.h>
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 
27 int
main(int argc,char * argv[])28 main(int argc, char *argv[]) {
29 	printf("\n");
30 #ifdef __LP64__
31         printf("System: 64 bit\n");
32 #else
33         printf("System: 32 bit\n");
34 #endif
35 
36 #if BYTE_ORDER == BIG_ENDIAN
37         printf("Host byte order: Big Endian\n");
38 #endif
39 #if BYTE_ORDER == LITTLE_ENDIAN
40         printf("Host byte order: Little Endian\n");
41 #endif
42 	printf("\n");
43 	printf("char:\t\t%2d (%3d bits)\n", sizeof(char), sizeof(char) * 8);
44 	printf("short:\t\t%2d (%3d bits)\n", sizeof(short), sizeof(short) * 8);
45 	printf("int:\t\t%2d (%3d bits)\n", sizeof(int), sizeof(int) * 8);
46 	printf("long:\t\t%2d (%3d bits)\n", sizeof(long), sizeof(long) * 8);
47 	printf("long long:\t%2d (%3d bits)\n", sizeof(long long), sizeof(long long) * 8);
48 	printf("\n");
49 
50 	printf("float:\t\t%2d (%3d bits)\n", sizeof(float), sizeof(float) * 8);
51 	printf("double:\t\t%2d (%3d bits)\n", sizeof(double), sizeof(double) * 8);
52 	printf("long double:\t%2d (%3d bits)\n", sizeof(long double), sizeof(long double) * 8);
53 	printf("\n");
54 
55 	printf("wchar_t:\t%2d (%3d bits)\n", sizeof(wchar_t), sizeof(wchar_t) * 8);
56 	printf("size_t:\t\t%2d (%3d bits)\n", sizeof(size_t), sizeof(size_t) * 8);
57 	printf("_Bool:\t\t%2d (%3d bits)\n", sizeof(_Bool), sizeof(_Bool) * 8);
58 	printf("\n");
59 
60 	printf("int8_t:\t\t%2d (%3d bits)\n", sizeof(int8_t), sizeof(int8_t) * 8);
61 	printf("int16_t:\t%2d (%3d bits)\n", sizeof(int16_t), sizeof(int16_t) * 8);
62 	printf("int32_t:\t%2d (%3d bits)\n", sizeof(int32_t), sizeof(int32_t) * 8);
63 	printf("int64_t:\t%2d (%3d bits)\n", sizeof(int64_t), sizeof(int64_t) * 8);
64 #ifdef __LP64__
65 	printf("__int128_t:\t%2d (%3d bits)\n", sizeof(__int128_t), sizeof(__int128_t) * 8);
66 	printf("\n");
67 #endif
68 	printf("int_fast8_t:\t%2d (%3d bits)\n", sizeof(int_fast8_t), sizeof(int_fast8_t) * 8);
69 	printf("int_fast16_t:\t%2d (%3d bits)\n", sizeof(int_fast16_t), sizeof(int_fast16_t) * 8);
70 	printf("int_fast32_t:\t%2d (%3d bits)\n", sizeof(int_fast32_t), sizeof(int_fast32_t) * 8);
71 	printf("int_fast64_t:\t%2d (%3d bits)\n", sizeof(int_fast64_t), sizeof(int_fast64_t) * 8);
72 	printf("\n");
73 	printf("int_least8_t:\t%2d (%3d bits)\n", sizeof(int_least8_t), sizeof(int_least8_t) * 8);
74 	printf("int_least16_t:\t%2d (%3d bits)\n", sizeof(int_least16_t), sizeof(int_least16_t) * 8);
75 	printf("int_least32_t:\t%2d (%3d bits)\n", sizeof(int_least32_t), sizeof(int_least32_t) * 8);
76 	printf("int_least64_t:\t%2d (%3d bits)\n", sizeof(int_least64_t), sizeof(int_least64_t) * 8);
77 	printf("\n");
78 	printf("intmax_t:\t%2d (%3d bits)\n", sizeof(intmax_t), sizeof(intmax_t) * 8);
79 }
80 
81 
82