On 8/23/22 15:16, Alejandro Colomar wrote:
I.e., AFAIK, my_imaxabs(++x) would only do the ++ once, right? Is that what you were suggesting?
If that's what you meant, the macro seems safe: $ cat imaxabs.c #include <stdint.h> #include <stdio.h> #include <stdlib.h> #define my_imaxabs(j) _Generic(INTMAX_C(0), \ long: labs(j), \ long long: llabs(j) \ /* long long long: lllabs(j) */ \ ) int main(void) { off_t a; a = (intmax_t) -1; printf("imaxabs(%jd) == %jd\n", (intmax_t) -2, my_imaxabs(--a)); exit(EXIT_SUCCESS); } $ cc -Wall -Wextra imaxabs.c $ ./a.out imaxabs(-2) == 2 Cheers, Alex -- Alejandro Colomar <http://www.alejandro-colomar.es/>
Attachment:
OpenPGP_signature
Description: OpenPGP digital signature