[Cfp-interest] _Generic

Fred J. Tydeman tydeman at tybor.com
Tue Feb 20 17:38:50 PST 2018


On Tue, 20 Feb 2018 14:32:31 -0600 Rajan Bhakta wrote:
>
>    Fred, Rajan: Check if the _Generic replacement suppress macro 
>expansion.

Based upon my testing of gcc, clang, and sun's C compilers,
macros are suppressed.  This code prints j=3

#include <stdio.h>

static int bf(int x){
  return x;
}

static int bd(int x){
  return x+x;
}

int main(void){
  int a = 0;
  int j;
#define a(y) 1
#define bf(y) a(y)
#define b(X) _Generic( (X),             \
                       int : bf,        \
                       default : bd     \
                       )(X)
  j = b(3);
  (void)printf("j=%i\n", j);
  return 0;
}


---
Fred J. Tydeman        Tydeman Consulting
tydeman at tybor.com      Testing, numerics, programming
+1 (702) 608-6093      Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.



More information about the Cfp-interest mailing list