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


Groups > comp.lang.c > #162569

Re: Working code

From Andrey Tarasevich <andreytarasevich@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Working code
Date 2021-09-01 20:57 -0700
Organization A noiseless patient Spider
Message-ID <sgpi2p$kd1$1@dont-email.me> (permalink)
References <sgouhf$8i2$1@z-news.wcss.wroc.pl> <86fsunx2yy.fsf@linuxsc.com>

Show all headers | View raw


On 9/1/2021 4:58 PM, Tim Rentsch wrote:
>> The following is simplified version of "working code":  it
>> is more than 20 years old (probably closer to 30 years old)
>> and apparently did what its author intended:
>>
>> int (*handlers[2])();
>>
>> #define DO_IT(n)   ((p = handlers[n]) ? (*p)() : 0)
>>
>> static void foo() {
>>      register int (*p)();
>>      register int bar = DO_IT(0) | DO_IT(1);
>>      /* ... */
>>      /* Use of bar */
>> }
>>
>> /* Code that fills 'handlers' and calls foo() */
>>
>> I wonder what you think about this code?
> 
> I think it has undefined behavior, and needlessly so:
> 
>      #define DO_IT(n)   (handlers[n] ? handlers[n]() : 0)
> 
>      ...

That intermediate variable `p` is indeed completely unnecessary. But 
where did you find undefined behavior in the original version?

-- 
Best regards,
Andrey Tarasevich

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


Thread

Working code antispam@math.uni.wroc.pl - 2021-09-01 22:23 +0000
  Re: Working code Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-09-01 16:58 -0700
    Re: Working code Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-09-01 20:57 -0700
      Re: Working code Ike Naar <ike@rie.sdf.org> - 2021-09-02 05:22 +0000
        Re: Working code Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-09-01 22:33 -0700
        Re: Working code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-09-02 11:54 +0100
          Re: Working code Richard Damon <Richard@Damon-Family.org> - 2021-09-02 07:08 -0400
            Re: Working code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-09-02 13:37 +0100
              Re: Working code James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-02 12:03 -0400
              Re: Working code Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-09-02 09:57 -0700
  Re: Working code Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-09-01 21:02 -0700
    Re: Working code John McCue <jmccue@obsd2.mhome.org> - 2021-09-02 13:31 +0000

csiph-web