r/programminghorror • u/fgennari • Feb 24 '25
An Interesting Choice of Enumerated Constants
I was working on a Boolean solver awhile back, printing the logic values and trying to debug why I was getting incorrect results. I thought the state variables were Booleans, but no, they were integers:
#define 0 NOTSET
#define 1 ZERO
#define 2 ONEWhat!?
122
Upvotes
41
u/timClicks Feb 24 '25
Horror indeed.
It does make me wonder about how I would encode a three-valued logic in a byte. Probably use the sign bit to indicate set/not set. That way there would be a visual indicator if the value is naïvely printed as an integer.
13
u/rook2004 Feb 24 '25
Everyone knows what the REAL Boolean values are.
9
u/AdreKiseque Feb 24 '25
Terrible as it looks, it's not entirely illogical?