Re: [PATCH v2] _Generic.3: New page documenting _Generic()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux