Deutsch English Français Italiano |
<vr02rt$alaa$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: Re: Concatenated if and preprocessor Date: Thu, 13 Mar 2025 12:19:30 -0400 Organization: A noiseless patient Spider Lines: 37 Message-ID: <vr02rt$alaa$1@dont-email.me> References: <vquuhg$34o8d$2@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 14 Mar 2025 03:04:46 +0100 (CET) Injection-Info: dont-email.me; posting-host="e77f647353e4cc7e3fe3e1d14aedc79e"; logging-data="349514"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Z0hJaa2mj0UDO+OkG/yr/1zb8hon9KF8=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:jkYnBRII5ZNY8xtKNduTPcCPbdc= Content-Language: en-US In-Reply-To: <vquuhg$34o8d$2@dont-email.me> 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