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. If ccan/endian/endian.h is included,
13 * it also provides be32/le32 for explicitly annotating types of specific
16 * Include this header, if only to stop people using these identifiers
23 * #include <ccan/short_types/short_types.h>
25 * // Print nonsensical numerical comparison of POSIX vs. short_types.
26 * #define stringify_1(x) #x
27 * #define stringify(x) stringify_1(x)
29 * static void evaluate(size_t size, const char *posix, const char *sht,
30 * unsigned int *posix_total, unsigned int *sht_total,
31 * unsigned int *size_total)
33 * printf("\t%ssigned %s: POSIX %zu%%, short %zu%%\n",
34 * sht[0] == 'u' ? "un" : "",
36 * strlen(posix)*100 / size,
37 * strlen(sht)*100 / size);
38 * *posix_total += strlen(posix);
39 * *sht_total += strlen(sht);
40 * *size_total += size;
43 * #define EVALUATE(psx, short, pt, st, t) \
44 * evaluate(sizeof(psx), stringify(psx), stringify(sht), pt, st, t)
48 * unsigned int posix_total = 0, sht_total = 0, size_total = 0;
50 * printf("Comparing size of type vs size of name:\n");
52 * EVALUATE(uint8_t, u8, &posix_total, &sht_total, &size_total);
53 * EVALUATE(int8_t, s8, &posix_total, &sht_total, &size_total);
54 * EVALUATE(uint16_t, u16, &posix_total, &sht_total, &size_total);
55 * EVALUATE(int16_t, s16, &posix_total, &sht_total, &size_total);
56 * EVALUATE(uint32_t, u32, &posix_total, &sht_total, &size_total);
57 * EVALUATE(int32_t, s32, &posix_total, &sht_total, &size_total);
58 * EVALUATE(uint64_t, u64, &posix_total, &sht_total, &size_total);
59 * EVALUATE(int64_t, s64, &posix_total, &sht_total, &size_total);
61 * printf("Conclusion:\n"
62 * "\tPOSIX is %u%% LESS efficient than binary.\n"
63 * "\tshort_types.h is %u%% MORE efficient than binary.\n",
64 * (posix_total - size_total) * 100 / size_total,
65 * (size_total - sht_total) * 100 / size_total);
69 * License: CC0 (Public domain)
70 * Author: Rusty Russell <rusty@rustcorp.com.au>
72 int main(int argc, char *argv[])
77 if (strcmp(argv[1], "depends") == 0) {
81 if (strcmp(argv[1], "testdepends") == 0) {
82 printf("ccan/endian\n");