Sujet : Re: Concatenated if and preprocessor
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 13. Mar 2025, 17:19:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vr02rt$alaa$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 3/13/25 11:44, pozz wrote:
Consider this code:
if (cond1) {
...
} else if (cond2) {
...
} else if (cond3) {
...
}
I want to activate every single if with a macro preprocessor. All the
combinations are possible: only the first, only the second, only the
third, the first and second... and so on.
What's the best method to have a clean code that is always compiled
without errors?
The cleanest way to do this involves trusting the compiler to quietly
remove unused branches:
#ifdef COND1
if (cond1) }
} else
#endif
#ifdef COND2
if (cond2) {
} else
#endif
#ifdef COND3
if (cond3 ) {
}
#else
; // Alternatively, use {}
#endif