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


Groups > comp.lang.c > #162562

Re: Working code

Path csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Working code
Date Wed, 01 Sep 2021 16:58:45 -0700
Organization A noiseless patient Spider
Lines 27
Message-ID <86fsunx2yy.fsf@linuxsc.com> (permalink)
References <sgouhf$8i2$1@z-news.wcss.wroc.pl>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info reader02.eternal-september.org; posting-host="96acc23d7407cde8c2bef4c22c59e469"; logging-data="11197"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dkrcB22Y0+j0UUE4tN2zhg7yki9mrayg="
User-Agent Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock sha1:cDvFbdFZsS9wBrsuzop5DQSREGw= sha1:wc3IUHX1We4i/0NevaLghIlGEIA=
Xref csiph.com comp.lang.c:162562

Show key headers only | View raw


antispam@math.uni.wroc.pl writes:

> 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)

    ...

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