Advertisement
Guest User

Untitled

a guest
Jan 13th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. typedef struct ball {} Ball;
  2. typedef struct point {} Point;
  3.  
  4. void destroy_ball()
  5. {
  6.     puts("Ball putt, neue kaufen.");
  7. }
  8.  
  9. void destroy_point()
  10. {
  11.     puts("Point futsch, was tun...");
  12. }
  13.  
  14. #define type(x) _Generic((x), Point: "Point", Ball: "Ball", default: ":(")
  15.  
  16. #define n_args(...) n_args_impl(0, __VA_ARGS__, 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
  17. #define n_args_impl(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,N,...) N
  18. #define clean_up(args...) clean_up_helper(n_args(args), args);
  19.  
  20. static inline void clean_up_helper(unsigned int arg_c, ...)
  21. {
  22.     va_list vl;
  23.     va_start(vl, arg_c);
  24.  
  25.     for (unsigned int i = 0; i < arg_c; ++i)
  26.     {
  27.         /*
  28.         ??type?? arg = va_arg(vl, ??type??);
  29.  
  30.         wenn strcmp(type(x), "Ball") == 0
  31.                 destroy_ball
  32.                 ...
  33.         */
  34.     }
  35.     va_end(vl);
  36. }
  37.  
  38. int main(void)
  39. {
  40.     Ball b;
  41.     Point p;
  42.     clean_up(b, p);
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement