| Deutsch English Français Italiano |
|
<86jz8rshnk.fsf@linuxsc.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups: comp.lang.c
Subject: Re: Concatenated if and preprocessor
Date: Fri, 14 Mar 2025 09:26:07 -0700
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <86jz8rshnk.fsf@linuxsc.com>
References: <vquuhg$34o8d$2@dont-email.me> <868qp8txwz.fsf@linuxsc.com> <vqvph8$3sjj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Fri, 14 Mar 2025 17:26:08 +0100 (CET)
Injection-Info: dont-email.me; posting-host="825d11fa9501a89399e86bed31f148c6";
logging-data="1735535"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IQ5rOf2FiB2ThEfnFtre8DlkvqBG13P0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:EVCwmCmyzdt3eSzPGGif7Y2n51c=
sha1:aYtIhM2b2FmnGEQIBrW2xREPEHA=
Bytes: 2590
Lynn McGuire <lynnmcguire5@gmail.com> writes:
> On 3/13/2025 4:37 PM, Tim Rentsch wrote:
>
>> pozz <pozzugno@gmail.com> writes:
>>
>>> 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?
>>
>> if ( ..bypass all further tests.. ) {
>> // for a "skip all conditional segments" case (if needed)
>> ...
>>
>> #if TEST_1
>> } else if (cond1) {
>> ...
>> #endif
>>
>> #if TEST_2
>> } else if (cond2) {
>> ...
>> #endif
>>
>> #if TEST_3
>> } else if (cond3) {
>> ...
>> #endif
>>
>> } else {
>> // for a "no conditional segment" ran case (if needed)
>> ...
>> }
>> >
>> Having said that, it's hard to imagine a scenario where doing
>> something like this is the best way to solve the higher level
>> problem. It is almost certainly better to rethink the reasoning
>> that resulted in choosing this scheme, and find a way to avoid it.
>
> It is code that must run on several platforms.
Yes, I already understood that. The point of my comment is
not to eliminate the preprocessor dependencies but to express
them in a more aesthetically pleasing way.