CodeSOD: Columns of a Constant Length
Today's submitter goes by "[object Object]", which I appreciate the JavaScript gag even when they send us C code.
This particular bit of C code exists to help output data in fixed-width files. What you run into, with fixed-width files, is that it becomes very important to properly pad all your columns. It's not a difficult programming challenge, but it's also easy to make mistakes that cause hard-to-spot bugs. And given that most systems using fixed-width files are legacy systems with their own idiosyncrasies, things could easily go wrong.
Things go more wrong when you don't actually know the right way to pad strings. Thus this excerpt from constants.h.
#define LABEL_SIZE1 1 #define LABEL_SIZE2 2 #define LABEL_SIZE3 3 #define LABEL_SIZE4 4 #define LABEL_SIZE5 5 #define LABEL_SIZE6 6 #define LABEL_SIZE7 7 #define LABEL_SIZE8 8 #define LABEL_SIZE9 9 #define LABEL_SIZE10 10 #define LABEL_SIZE11 11 #define LABEL_SIZE12 12 #define LABEL_SIZE14 14 #define LABEL_SIZE15 15 #define LABEL_SIZE16 16 #define LABEL_SIZE21 21 #define LABEL_SIZE20 20 #define LABEL_SIZE23 23 #define LABEL_SIZE24 24 #define LABEL_SIZE25 25 #define LABEL_SIZE30 30 #define LABEL_SIZE31 31 #define LABEL_SIZE32 32 #define LABEL_SIZE33 33 #define LABEL_SIZE37 37 #define LABEL_SIZE39 39 #define LABEL_SIZE40 40 #define LABEL_SIZE43 43 #define LABEL_SIZE45 45 #define LABEL_SIZE48 48 #define LABEL_SIZE50 50 #define LABEL_SIZE53 53 #define LABEL_SIZE73 73 #define LABEL_SIZE80 80 #define LABEL_SIZE121 121 #define LABEL_SIZE100 100 #define LABEL_SIZE149 149 #define LABEL_SIZE150 150 #define LABEL_SIZE170 170 #define LABEL_SIZE175 175 #define LABEL_SIZE205 205 #define LABEL_SIZE208 208 #define LABEL_SIZE723 723 #define LABEL_SIZE725 725 #define LABEL_SIZE753 753 #define LABEL_SIZE825 825 #define LABEL_SIZE853 853 #define SPACE_1 " " #define SPACE_2 " " #define SPACE_3 " " #define SPACE_4 " " #define SPACE_5 " " #define SPACE_8 " " #define SPACE_10 " " #define SPACE_11 " " #define SPACE_12 " " #define SPACE_13 " " #define SPACE_14 " " #define SPACE_15 " " #define SPACE_19 " " #define SPACE_20 " " #define SPACE_21 " " #define SPACE_23 " " #define SPACE_25 " " #define SPACE_29 " " #define SPACE_30 " " #define SPACE_31 " " #define SPACE_32 " " #define SPACE_37 " " #define SPACE_39 " " #define SPACE_41 " " #define SPACE_53 " " #define SPACE_57 " " #define ZERO_1 "0" #define ZERO_2 "00" #define ZERO_3 "000" #define ZERO_4 "0000" #define ZERO_5 "00000" #define ZERO_8 "00000000" #define ZERO_10 "0000000000" #define ZERO_11 "00000000000" #define ZERO_14 "00000000000000" #define ZERO_29 "00000000000000000000000000000" #define NINE_11 "99999999999" #define NINE_29 "99999999999999999999999999999" // Min max values #define MIN_MINUS1 -1 #define MIN_0 0 #define MIN_1 1 #define MIN_111 111 #define MAX_0 0 #define MAX_1 1 #define MAX_2 2 #define MAX_3 3 #define MAX_4 4 #define MAX_7 7 #define MAX_9 9 #define MAX_12 12 #define MAX_15 15 #define MAX_63 63 #define MAX_99 99 #define MAX_114 114 #define MAX_127 127 #define MAX_255 255 #define MAX_256 256 #define MAX_999 999 #define MAX_1023 1023 #define MAX_4095 4095 #define MAX_9999 9999 #define MAX_16383 16383 #define MAX_65535 65535 #define MAX_9_5 99999 #define MAX_9_6 999999 #define MAX_9_7 9999999 #define MAX_9_8 99999999 #define MAX_9_9 999999999 #define MAX_9_10 9999999999 #define MAX_9_11 99999999999
The full file is 500 lines long, all in this pattern. It's also delightfully meta: these constants are used for generating fixed-width files, and this file is itself a fixed-width file, thanks to the developer wearing their tab key out.
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!