C language macro magical writing: Block as parameter, half a functional programming?

I want to write test code to do a few cycles, each time writing `for (size_t i = 0; i <n; i ++)` very annoying, then had an idea, can not be achieved using the macro, and then wrote:

#define repeat(n, statements) for(size_t i = 0; i < n; i++) { statements }

Then actually really executes the specified statements (block), as found in the New World, like, ha ha, I do not know if that is not half a pseudo functional programming. test:

repeat(10, {
    puts("hello world");
});

Then it will print 10 lines of the hello world

 

Guess you like

Origin www.cnblogs.com/yuanyb/p/11074590.html