[ prog / sol / mona ]

prog


Post macros.

33 2020-08-15 11:35

>>32 This allows to create more complex variants of the loop, much neater than just prepending for()

#define unwrap(args...) args
#define loop(s,n,args...) for(int i=s;i<n;i++){args;}
#define gloop(cond,args...) for(unwrap cond){args;}
#define array(type,name,args...) type name[] ={args};
#define arrsize(arr) (sizeof(arr)/sizeof(arr[0]))
#define limitprint(arr,cond,code...) gloop((int i=0;i<arrsize(arr);i++),(code),(arr[i] cond?printf("%d,",arr[i]):0))

array(int,arr,1,3,4,6,2,7,9,1,0,-1);
limitprint(arr,>6,(arr[i]*=2));

The above results in:
int arr[] ={1,3,4,6,2,7,9,1,0,-1};;
for(int i=0;i<(sizeof(arr)/sizeof(arr[0]));i++){((arr[i]*=2)),(arr[i] >6?printf("%d,",arr[i]):0);};

40


VIP:

do not edit these