mytype.c 412 B

123456789101112131415161718192021
  1. // mytype.c
  2. #include <stdio.h>
  3. #define MYTYPE(X) _Generic((X),\
  4. int: "int",\
  5. float : "float",\
  6. double: "double",\
  7. default: "other"\
  8. )
  9. int main(void)
  10. {
  11. int d = 5;
  12. printf("%s\n", MYTYPE(d)); // d is type int
  13. printf("%s\n", MYTYPE(2.0*d)); // 2.0* d is type double
  14. printf("%s\n", MYTYPE(3L)); // 3L is type long
  15. printf("%s\n", MYTYPE(&d)); // &d is type int *
  16. return 0;
  17. }