6 * short_types - shorter names for standard integer types
8 * "C is a Spartan language, and so should your naming be."
11 * The short_types header provides for convenient abbreviations for the
12 * posixly-damned uint32_t types. It also provides be32/le32 for explicitly
13 * annotating types of specific endian.
15 * Include this header, if only to stop people using these identifiers
22 * #include <ccan/short_types/short_types.h>
24 * // Print nonsensical numerical comparison of POSIX vs. short_types.
25 * #define stringify_1(x) #x
26 * #define stringify(x) stringify_1(x)
28 * static void evaluate(size_t size, const char *posix, const char *sht,
29 * unsigned int *posix_total, unsigned int *sht_total,
30 * unsigned int *size_total)
32 * printf("\t%ssigned %s: POSIX %i%%, short %i%%\n",
33 * sht[0] == 'u' ? "un" : "",
35 * strlen(posix)*100 / size,
36 * strlen(sht)*100 / size);
37 * *posix_total += strlen(posix);
38 * *sht_total += strlen(sht);
39 * *size_total += size;
42 * #define EVALUATE(psx, short, pt, st, t) \
43 * evaluate(sizeof(psx), stringify(psx), stringify(sht), pt, st, t)
47 * unsigned int posix_total = 0, sht_total = 0, size_total = 0;
49 * printf("Comparing size of type vs size of name:\n");
51 * EVALUATE(uint8_t, u8, &posix_total, &sht_total, &size_total);
52 * EVALUATE(int8_t, s8, &posix_total, &sht_total, &size_total);
53 * EVALUATE(uint16_t, u16, &posix_total, &sht_total, &size_total);
54 * EVALUATE(int16_t, s16, &posix_total, &sht_total, &size_total);
55 * EVALUATE(uint32_t, u32, &posix_total, &sht_total, &size_total);
56 * EVALUATE(int32_t, s32, &posix_total, &sht_total, &size_total);
57 * EVALUATE(uint64_t, u64, &posix_total, &sht_total, &size_total);
58 * EVALUATE(int64_t, s64, &posix_total, &sht_total, &size_total);
60 * printf("Conclusion:\n"
61 * "\tPOSIX is %u%% LESS efficient than binary.\n"
62 * "\tshort_types.h is %u%% MORE efficient than binary.\n",
63 * (posix_total - size_total) * 100 / size_total,
64 * (size_total - sht_total) * 100 / size_total);
68 * License: Public domain
69 * Author: Rusty Russell <rusty@rustcorp.com.au>
71 int main(int argc, char *argv[])
76 if (strcmp(argv[1], "depends") == 0) {