1#include "config.h" 2#include <stdio.h> 3#include <string.h> 4 5/** 6 * short_types - shorter names for standard integer types 7 * 8 * "C is a Spartan language, and so should your naming be." 9 * -- Linus Torvalds 10 * 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 14 * endian. 15 * 16 * Include this header, if only to stop people using these identifiers 17 * for other things! 18 * 19 * Example: 20 * #include <stdint.h> 21 * #include <string.h> 22 * #include <stdio.h> 23 * #include <ccan/short_types/short_types.h> 24 * 25 * // Print nonsensical numerical comparison of POSIX vs. short_types. 26 * #define stringify_1(x) #x 27 * #define stringify(x) stringify_1(x) 28 * 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) 32 * { 33 * printf("\t%ssigned %s: POSIX %zu%%, short %zu%%\n", 34 * sht[0] == 'u' ? "un" : "", 35 * sht+1, 36 * strlen(posix)*100 / size, 37 * strlen(sht)*100 / size); 38 * *posix_total += strlen(posix); 39 * *sht_total += strlen(sht); 40 * *size_total += size; 41 * } 42 * 43 * #define EVALUATE(psx, short, pt, st, t) \ 44 * evaluate(sizeof(psx), stringify(psx), stringify(sht), pt, st, t) 45 * 46 * int main(void) 47 * { 48 * unsigned int posix_total = 0, sht_total = 0, size_total = 0; 49 * 50 * printf("Comparing size of type vs size of name:\n"); 51 * 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); 60 * 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); 66 * return 0; 67 * } 68 * 69 * License: CC0 (Public domain) 70 * Author: Rusty Russell <rusty@rustcorp.com.au> 71 */ 72int main(int argc, char *argv[]) 73{ 74 if (argc != 2) 75 return 1; 76 77 if (strcmp(argv[1], "depends") == 0) { 78 return 0; 79 } 80 81 if (strcmp(argv[1], "testdepends") == 0) { 82 printf("ccan/endian\n"); 83 return 0; 84 } 85 86 return 1; 87} 88