#How do I achieve true macro-free code?

9 messages · Page 1 of 1 (latest)

fresh sable
#

For example, what would be the C++ way to replace C-style code smells like:

#if (__linux__)
#include <cpuid.h>
#endif

with something along the lines of:

if constexpr (__linux__) {
#include <cpuid.h>
}

obviously this doesn't work, but if there's no cure, what options do I have to avoid macros as much as possible?

charred graniteBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

small vault
#

and you kinda have to, as the preprocessor gets run before the compiler

glacial fern
#

There is no such thing in C++. Also I don't see how the suggestion is an improvement.

small vault
#

in general there is a mantra to avoid macros but that generally refers to using it for codegen imho, this is a perfectly acceptable place for it

#

or well codegen isn't the proper word, but for making well macros

fresh sable
#

alr ty

#

!solved