News for hackers. Stuff that matters.
Re:Maximal Min() and Max() by layer8 on Thursday August 08, 2024 @12:18PM (#41193176)
This reminds me of how ~25 years ago I wrote little C macro library to perform safe (non-overflowing, and/or saturating) integer arithmetics and comparisons, however the small application I wanted to use it in had the compiler crash after 2-3 hours due to insufficient RAM+swap when compiling a single source file using those macros. It turned out the macro expansions made the translation unit grow to GB size, which must have been 4-5 orders of magnitude over its original size.
Re:Maximal Min() and Max() by sapiogram on Thursday August 08, 2024 @12:44PM (#41193515)
How did that end up happening? Did you define addition recursively or something?
Re:Maximal Min() and Max() by layer8 on Thursday August 08, 2024 @12:53PM (#41193625)
The macros automatically derived the signedness and the minimum and maximum value of the integral types involved, in a way that didn’t made platform-specific assumptions like two’s complement or no padding bits. Cases like comparing signed long to unsigned long also needed extra logic, due to there being no larger type that encompasses both. I don’t remember the details, but it did have a significant number of nested macro invocations.