Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #391175

Re: Concatenated if and preprocessor

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Concatenated if and preprocessor
Date 2025-03-14 09:26 -0700
Organization A noiseless patient Spider
Message-ID <86jz8rshnk.fsf@linuxsc.com> (permalink)
References <vquuhg$34o8d$2@dont-email.me> <868qp8txwz.fsf@linuxsc.com> <vqvph8$3sjj$1@dont-email.me>

Show all headers | View raw


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.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Concatenated if and preprocessor pozz <pozzugno@gmail.com> - 2025-03-13 16:44 +0100
  Re: Concatenated if and preprocessor David Brown <david.brown@hesbynett.no> - 2025-03-13 16:55 +0100
  Re: Concatenated if and preprocessor scott@slp53.sl.home (Scott Lurndal) - 2025-03-13 16:11 +0000
  Re: Concatenated if and preprocessor James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-03-13 12:07 -0400
  Re: Concatenated if and preprocessor Kaz Kylheku <643-408-1753@kylheku.com> - 2025-03-13 16:30 +0000
  Re: Concatenated if and preprocessor bart <bc@freeuk.com> - 2025-03-13 17:29 +0000
  Re: Concatenated if and preprocessor Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-03-13 14:37 -0700
    Re: Concatenated if and preprocessor Lynn McGuire <lynnmcguire5@gmail.com> - 2025-03-13 18:25 -0500
      Re: Concatenated if and preprocessor Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-03-14 09:26 -0700
  Re: Concatenated if and preprocessor James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-03-13 12:19 -0400
  Re: Concatenated if and preprocessor pozz <pozzugno@gmail.com> - 2025-03-14 13:02 +0100
    Re: Concatenated if and preprocessor David Brown <david.brown@hesbynett.no> - 2025-03-14 14:13 +0100
    Re: Concatenated if and preprocessor Dan Purgert <dan@djph.net> - 2025-03-14 13:44 +0000
    Re: Concatenated if and preprocessor Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-03-14 09:44 -0700
      Re: Concatenated if and preprocessor Richard Harnden <richard.nospam@gmail.invalid> - 2025-03-14 18:15 +0000
        Re: Concatenated if and preprocessor Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-03-14 13:40 -0700
          Re: Concatenated if and preprocessor Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-14 14:10 -0700
            Re: Concatenated if and preprocessor Richard Harnden <richard.nospam@gmail.invalid> - 2025-03-14 21:31 +0000
              Re: Concatenated if and preprocessor Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-03-14 15:29 -0700
                Re: Concatenated if and preprocessor David Brown <david.brown@hesbynett.no> - 2025-03-15 17:32 +0100
            Re: Concatenated if and preprocessor Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-03-14 15:57 -0700
              Re: Concatenated if and preprocessor Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-14 16:27 -0700
                Re: Concatenated if and preprocessor scott@slp53.sl.home (Scott Lurndal) - 2025-03-15 15:06 +0000
                Re: Concatenated if and preprocessor Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-03-15 08:49 -0700
                Re: Concatenated if and preprocessor scott@slp53.sl.home (Scott Lurndal) - 2025-03-15 17:28 +0000
            Re: Concatenated if and preprocessor David Brown <david.brown@hesbynett.no> - 2025-03-15 17:28 +0100
        Re: Concatenated if and preprocessor Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-03-15 07:03 +0000
    Re: Concatenated if and preprocessor Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-14 11:10 -0700
    Re: Concatenated if and preprocessor James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-03-14 23:20 -0400

csiph-web