Cooler_

Free_all macro l33t

Jan 13th, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. // testei com  argv -std=gnu99
  2. #include <stdio.h>
  3. #include <stdlib.h> //malloc, free
  4.  
  5. #define Fn_apply(type, fn, ...) { \
  6.  void *stopper_for_apply = (int[]){0};  \
  7.  type **list_for_apply = (type*[]){__VA_ARGS__, stopper_for_apply};  \
  8.  for (int i=0; list_for_apply[i] != stopper_for_apply; i++)  \
  9.   fn(list_for_apply[i]);    \
  10.  }
  11.  
  12. #define Free_all(...) Fn_apply(void, free, __VA_ARGS__);
  13.  
  14. int main()
  15. {
  16.  double *x= malloc(10);
  17.  double *y= malloc(100);
  18.  double *z= malloc(1000);
  19.  Free_all(x, y, z);
  20. }
Add Comment
Please, Sign In to add comment