clibs
Tiny but handy utility libraries for C
Loading...
Searching...
No Matches
clibs_control_structure.h File Reference

Common control structures. More...

#include <stddef.h>
Include dependency graph for clibs_control_structure.h:

Go to the source code of this file.

Macros

#define TIMES(count, block)
 Repeat a block of code a given number of times.

Detailed Description

Common control structures.

Author
ByteBard
Note
This header demonstrates that language-like control structures can technically be implemented using macros in C.

However, this pattern can easily lead to code that is difficult to read, debug, and maintain. Because of this risk, we will NOT introduce any additional "language block" style macros in this project.

This macro exists purely as a technical demonstration of what is possible in C, not as a recommended pattern for general use.

Warning
Avoid using this macro in production code. Control-flow macros can easily evolve into a macro-based DSL and make the codebase harder to understand.

Macro Definition Documentation

◆ TIMES

#define TIMES ( count,
block )
Value:
do { \
for (size_t _clibs_times_i = 0; \
_clibs_times_i < (count); \
++_clibs_times_i) \
{ \
block; \
} \
} while (0)

Repeat a block of code a given number of times.

Parameters
countNumber of repetitions
blockCode block to execute