Here's a bit tricky one, because AFAIK there is no existing platform, where conditionally compiled part of the code would actually get included by compiler, so it is entirely up to the human review to see if it is correct.The purpose is to have abs function, which does not trigger undefined behavior with any user input, on any C99 standard compliant compiler, on any platform, and in the theoretical case of result not fitting in the return type, return maximum value that fits.Apart from any bugs, blunders etc, the real challenge is to come up with a (maybe theoretical) platform where the code doesn't produce desired result, or (hopefully) be reasonably certain that it works in all cases allowed by the standard.// function to review#include <inttypes.h>uintmax_t maxed_abs(intmax_t i) {    if (i < 0) {#if UINTMAX_MAX == INTMAX_MAX && INTMAX_MIN < -INTMAX_MAX        // catch the theoretical case of 2's complement platform,        // where unsigned and signed have same number of value bits        if (i == INTMAX_MIN) return UINTMAX_MAX;#endif        return -(uintmax_t)i;    }    return (uintmax_t)i;}// test code#include <stdio.h>int main(void){    printf(Enter int in range %jd .. %jd:\n > , INTMAX_MIN, INTMAX_MAX);    intmax_t i;    if (scanf(%jd, &i) == 1) {        printf(Result: |%jd| = %ju\n, i, maxed_abs(i));    }}
Safe, fully standards-following integer abs in C
c;integer;type safety