3 ms·
Can you provide an example of control structures that cannot be used in elegant manner without macros? I honestly fail to think of any example. However I gener
by mbel 10y ago
Can you provide an example of control structures that cannot be used in elegant manner without macros? I honestly fail to think of any example.
However I generally agree, that macros are pretty much unavoidable. Include guards are implemented using macro constants. It is pretty much the only portable way to force inlining (in some cases this might be necessary). Variadic macros are a easier to create that variadic functions (e.g. wrapper around fprintf for logging). And there is also the '_Generic' thing for people, who can use C11.
- fpoling 10y agoAnother unavoidable use of macros is to convert symbolic names into string literals or to enable warnings for printf wrappers in a portable code. As for include guards one has to look really hard [1] to get a compiler that does not support #pragma once. [1] - https://en.wikipedia.org/wiki/Pragma_once#Portability https://en.wikipedia.org/wiki/Pragma_once#Portability