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


Groups > comp.lang.c > #21522 > unrolled thread

Error returns and repeated code, GOTOs, etc.

Started bymike3 <mike4ty4@yahoo.com>
First post2012-05-29 22:44 -0700
Last post2012-06-06 08:12 -0700
Articles 20 on this page of 133 — 38 participants

Back to article view | Back to comp.lang.c


Contents

  Error returns and repeated code, GOTOs, etc. mike3 <mike4ty4@yahoo.com> - 2012-05-29 22:44 -0700
    Re: Error returns and repeated code, GOTOs, etc. Ike Naar <ike@sverige.freeshell.org> - 2012-05-30 06:38 +0000
    Re: Error returns and repeated code, GOTOs, etc. Nils M Holm <news2009@t3x.org> - 2012-05-30 06:57 +0000
    Re: Error returns and repeated code, GOTOs, etc. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-30 00:52 -0700
      Re: Error returns and repeated code, GOTOs, etc. mike3 <mike4ty4@yahoo.com> - 2012-05-30 01:50 -0700
    Re: Error returns and repeated code, GOTOs, etc. MarkBluemel <mark_bluemel@pobox.com> - 2012-05-30 09:55 +0100
      Re: Error returns and repeated code, GOTOs, etc. Willem <willem@toad.stack.nl> - 2012-05-30 09:18 +0000
        Re: Error returns and repeated code, GOTOs, etc. tom st denis <tom@iahu.ca> - 2012-05-30 05:16 -0700
          Re: Error returns and repeated code, GOTOs, etc. Willem <willem@toad.stack.nl> - 2012-05-30 16:26 +0000
            Re: Error returns and repeated code, GOTOs, etc. tom st denis <tom@iahu.ca> - 2012-06-01 08:05 -0700
              Re: Error returns and repeated code, GOTOs, etc. Willem <willem@toad.stack.nl> - 2012-06-03 11:24 +0000
            Re: Error returns and repeated code, GOTOs, etc. jgk@panix.com (Joe keane) - 2012-06-02 13:54 +0000
              Re: Error returns and repeated code, GOTOs, etc. Jean-Christophe <5.d@free.fr> - 2012-06-02 07:24 -0700
                Re: Error returns and repeated code, GOTOs, etc. jgk@panix.com (Joe keane) - 2012-06-02 16:37 +0000
                  Re: Error returns and repeated code, GOTOs, etc. Jean-Christophe <5.d@free.fr> - 2012-06-02 12:46 -0700
              Re: Error returns and repeated code, GOTOs, etc. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-02 15:42 +0100
                Re: Error returns and repeated code, GOTOs, etc. jgk@panix.com (Joe keane) - 2012-06-02 19:35 +0000
                  Re: Error returns and repeated code, GOTOs, etc. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-03 03:53 +0100
                    Re: Error returns and repeated code, GOTOs, etc. Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-06-11 18:10 +0300
                      Re: Error returns and repeated code, GOTOs, etc. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-11 16:19 +0100
              Re: Error returns and repeated code, GOTOs, etc. Martin Shobe <martin.shobe@yahoo.com> - 2012-06-02 19:27 +0000
                Re: Error returns and repeated code, GOTOs, etc. jgk@panix.com (Joe keane) - 2012-06-03 23:48 +0000
                  Re: Error returns and repeated code, GOTOs, etc. Ian Collins <ian-news@hotmail.com> - 2012-06-04 11:53 +1200
                  Re: Error returns and repeated code, GOTOs, etc. Martin Shobe <martin.shobe@yahoo.com> - 2012-06-04 03:32 +0000
      Re: Error returns and repeated code, GOTOs, etc. nick_keighley_nospam@hotmail.com - 2012-05-30 07:25 -0700
      Re: Error returns and repeated code, GOTOs, etc. falk@rahul.net (Edward A. Falk) - 2012-06-05 07:20 +0000
    Re: Error returns and repeated code, GOTOs, etc. Ian Collins <ian-news@hotmail.com> - 2012-05-30 21:50 +1200
      Re: Error returns and repeated code, GOTOs, etc. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-30 03:34 -0700
        Re: Error returns and repeated code, GOTOs, etc. Ian Collins <ian-news@hotmail.com> - 2012-05-30 22:57 +1200
        Re: Error returns and repeated code, GOTOs, etc. Willem <willem@toad.stack.nl> - 2012-05-30 11:04 +0000
        Re: Error returns and repeated code, GOTOs, etc. nick_keighley_nospam@hotmail.com - 2012-05-30 04:53 -0700
    Re: Error returns and repeated code, GOTOs, etc. "BartC" <bc@freeuk.com> - 2012-05-30 13:28 +0100
      Re: Error returns and repeated code, GOTOs, etc. mike3 <mike4ty4@yahoo.com> - 2012-05-30 13:57 -0700
    Re: Error returns and repeated code, GOTOs, etc. "io_x" <a@b.c.invalid> - 2012-05-30 15:19 +0200
      Re: Error returns and repeated code, GOTOs, etc. Mark Bluemel <mark.bluemel@googlemail.com> - 2012-05-31 01:10 -0700
      Re: Error returns and repeated code, GOTOs, etc. "io_x" <a@b.c.invalid> - 2012-06-02 17:34 +0200
        Re: Error returns and repeated code, GOTOs, etc. "io_x" <a@b.c.invalid> - 2012-06-03 10:33 +0200
    Re: Error returns and repeated code, GOTOs, etc. Ike Naar <ike@iceland.freeshell.org> - 2012-05-30 13:56 +0000
      Re: Error returns and repeated code, GOTOs, etc. Kulin <remailer@reece.net.au> - 2012-05-30 17:29 +0000
    Re: Error returns and repeated code, GOTOs, etc. ImpalerCore <jadill33@gmail.com> - 2012-05-30 07:13 -0700
      Re: Error returns and repeated code, GOTOs, etc. Thad Smith <ThadSmith@acm.org> - 2012-06-02 07:20 -0600
    Re: Error returns and repeated code, GOTOs, etc. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-30 16:37 +0100
    Re: Error returns and repeated code, GOTOs, etc. Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-05-30 19:05 +0200
    Re: Error returns and repeated code, GOTOs, etc. Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-31 13:19 -0700
      Re: Error returns and repeated code, GOTOs, etc. mike3 <mike4ty4@yahoo.com> - 2012-05-31 13:49 -0700
        Re: Error returns and repeated code, GOTOs, etc. "BartC" <bc@freeuk.com> - 2012-05-31 22:08 +0100
          Re: Error returns and repeated code, GOTOs, etc. mike3 <mike4ty4@yahoo.com> - 2012-05-31 16:08 -0700
        Re: Error returns and repeated code, GOTOs, etc. Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-31 17:34 -0700
        Re: Error returns and repeated code, GOTOs, etc. Willem <willem@toad.stack.nl> - 2012-06-01 07:40 +0000
    GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) mike3 <mike4ty4@yahoo.com> - 2012-05-31 16:39 -0700
      Re: GOTOs discovered in "real world" program! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-01 03:21 +0100
        Re: GOTOs discovered in "real world" program! mike3 <mike4ty4@yahoo.com> - 2012-06-01 03:49 -0700
          Re: GOTOs discovered in "real world" program! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-02 02:15 +0100
            Re: GOTOs discovered in "real world" program! mike3 <mike4ty4@yahoo.com> - 2012-06-01 19:45 -0700
              Re: GOTOs discovered in "real world" program! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-02 15:00 +0100
                Re: GOTOs discovered in "real world" program! mike3 <mike4ty4@yahoo.com> - 2012-06-02 16:44 -0700
                  Re: GOTOs discovered in "real world" program! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-03 03:51 +0100
        Re: GOTOs discovered in "real world" program! "Aaron W.  Hsu" <arcfide@sacrideo.us> - 2012-06-01 12:06 -0400
          Re: GOTOs discovered in "real world" program! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-02 02:01 +0100
            Re: GOTOs discovered in "real world" program! mike3 <mike4ty4@yahoo.com> - 2012-06-01 19:46 -0700
              Re: GOTOs discovered in "real world" program! mike3 <mike4ty4@yahoo.com> - 2012-06-01 21:19 -0700
                Re: GOTOs discovered in "real world" program! blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2012-06-02 16:35 +0000
              Re: GOTOs discovered in "real world" program! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-02 14:50 +0100
              Re: GOTOs discovered in "real world" program! Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-06-02 07:04 -0700
            Re: GOTOs discovered in "real world" program! "Aaron W. Hsu" <arcfide@sacrideo.us> - 2012-06-02 04:37 -0500
              Re: GOTOs discovered in "real world" program! mike3 <mike4ty4@yahoo.com> - 2012-06-02 03:40 -0700
                Re: GOTOs discovered in "real world" program! Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-02 14:46 +0100
                  Re: GOTOs discovered in "real world" program! "BartC" <bc@freeuk.com> - 2012-06-02 17:10 +0100
                  Re: GOTOs discovered in "real world" program! Robert Wessel <robertwessel2@yahoo.com> - 2012-06-02 11:35 -0500
      Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) "BartC" <bc@freeuk.com> - 2012-06-02 09:46 +0100
        Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) "io_x" <a@b.c.invalid> - 2012-06-03 10:43 +0200
          Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) "BartC" <bc@freeuk.com> - 2012-06-03 10:58 +0100
            Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) "io_x" <a@b.c.invalid> - 2012-06-03 17:18 +0200
            Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) jgk@panix.com (Joe keane) - 2012-06-04 20:40 +0000
              Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) jgk@panix.com (Joe keane) - 2012-06-05 01:03 +0000
                Re: GOTOs discovered in "real world" program! Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-06-04 21:36 -0600
                  Re: GOTOs discovered in "real world" program! jgk@panix.com (Joe keane) - 2012-06-05 15:13 +0000
                Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) Ike Naar <ike@sverige.freeshell.org> - 2012-06-05 08:12 +0000
                  Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) James Kuyper <jameskuyper@verizon.net> - 2012-06-05 06:00 -0400
              Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) jgk@panix.com (Joe keane) - 2012-06-05 02:05 +0000
                Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) Martin Shobe <martin.shobe@yahoo.com> - 2012-06-05 03:16 +0000
          Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) "io_x" <a@b.c.invalid> - 2012-06-03 17:30 +0200
            Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) Jean-Christophe <5.d@free.fr> - 2012-06-03 09:02 -0700
              Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-03 22:37 +0100
                Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) Ike Naar <ike@iceland.freeshell.org> - 2012-06-04 07:28 +0000
                Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.) Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-08 01:28 -0700
      Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) mike3 <mike4ty4@yahoo.com> - 2012-06-06 02:54 -0700
        Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-06 13:14 +0100
          Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) pete <pfiland@mindspring.com> - 2012-06-06 09:22 -0400
            Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Willem <willem@toad.stack.nl> - 2012-06-06 13:49 +0000
              Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Rui Maciel <rui.maciel@gmail.com> - 2012-06-06 14:56 +0100
              Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) James Kuyper <jameskuyper@verizon.net> - 2012-06-06 10:17 -0400
        Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Angel <angel+news@spamcop.net> - 2012-06-06 13:06 +0000
          Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) mike3 <mike4ty4@yahoo.com> - 2012-06-07 16:26 -0700
            Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Angel <angel+news@spamcop.net> - 2012-06-08 14:26 +0000
              Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) mike3 <mike4ty4@yahoo.com> - 2012-06-08 15:19 -0700
                Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Angel <angel+news@spamcop.net> - 2012-06-08 23:32 +0000
                Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) "BartC" <bc@freeuk.com> - 2012-06-09 01:14 +0100
                  Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Jean-Christophe <5.d@free.fr> - 2012-06-09 04:36 -0700
                  Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-06-09 05:54 -0700
                    Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) "BartC" <bc@freeuk.com> - 2012-06-09 16:12 +0100
                      Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-06-09 08:44 -0700
                        Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) "io_x" <a@b.c.invalid> - 2012-06-10 18:23 +0200
                          Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) "io_x" <a@b.c.invalid> - 2012-06-10 19:42 +0200
                            Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) "io_x" <a@b.c.invalid> - 2012-06-14 18:00 +0200
                          Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) nick_keighley_nospam@hotmail.com - 2012-06-11 01:14 -0700
                            Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) "io_x" <a@b.c.invalid> - 2012-06-12 08:01 +0200
                              Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) nick_keighley_nospam@hotmail.com - 2012-06-12 05:27 -0700
                            Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) "io_x" <a@b.c.invalid> - 2012-06-12 08:44 +0200
                    Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) jgk@panix.com (Joe keane) - 2012-06-11 17:24 +0000
                      Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) "BartC" <bc@freeuk.com> - 2012-06-11 19:02 +0100
                        Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) jgk@panix.com (Joe keane) - 2012-06-12 20:03 +0000
                          Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) nick_keighley_nospam@hotmail.com - 2012-06-13 00:58 -0700
                            Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) James Kuyper <jameskuyper@verizon.net> - 2012-06-13 06:37 -0400
                              Evil in Programming   Was: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) nick_keighley_nospam@hotmail.com - 2012-06-13 04:50 -0700
                            Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) gwowen <gwowen@gmail.com> - 2012-06-13 07:02 -0700
                            Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Les Cargill <lcargill99@comcast.com> - 2012-06-13 12:47 -0500
                              Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) James Kuyper <jameskuyper@verizon.net> - 2012-06-13 14:17 -0400
                                Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Willem <willem@toad.stack.nl> - 2012-06-13 19:44 +0000
                                  Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) James Kuyper <jameskuyper@verizon.net> - 2012-06-13 15:52 -0400
                                Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Les Cargill <lcargill99@comcast.com> - 2012-06-13 17:45 -0500
                                  Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) James Kuyper <jameskuyper@verizon.net> - 2012-06-13 19:07 -0400
                                Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) jgk@panix.com (Joe keane) - 2012-06-14 23:03 +0000
                                Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Kaz Kylheku <kaz@kylheku.com> - 2012-06-14 23:25 +0000
                                  Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Les Cargill <lcargill99@comcast.com> - 2012-06-14 19:25 -0500
                                    Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) 88888 Dihedral <dihedral88888@googlemail.com> - 2012-06-17 20:32 -0700
                                      Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) nick_keighley_nospam@hotmail.com - 2012-06-18 01:30 -0700
                                        Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) Les Cargill <lcargill99@comcast.com> - 2012-06-18 07:06 -0500
                            Re: Why was there a GOTO? Gareth Owen <gwowen@gmail.com> - 2012-06-13 19:57 +0100
                  Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!) jgk@panix.com (Joe keane) - 2012-06-10 16:56 +0000
    Another problem (was Re: Error returns and repeated code, GOTOs, etc.) mike3 <mike4ty4@yahoo.com> - 2012-05-31 16:46 -0700
      Re: Another problem (was Re: Error returns and repeated code, GOTOs, etc.) Ian Collins <ian-news@hotmail.com> - 2012-06-01 15:55 +1200
    Re: Error returns and repeated code, GOTOs, etc. gwowen <gwowen@gmail.com> - 2012-06-06 08:12 -0700

Page 5 of 7 — ← Prev page 1 2 3 4 [5] 6 7  Next page →


#21852 — Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)

FromMartin Shobe <martin.shobe@yahoo.com>
Date2012-06-05 03:16 +0000
SubjectRe: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)
Message-ID<jqjtn9$m2m$1@dont-email.me>
In reply to#21850
Joe keane wrote:

> In article <postconditions-20120605002952@ram.dialup.fu-berlin.de>,
> Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>>  and I am not aware of any source speaking of such /two/
>>  postconditions.
>
> http://en.wikipedia.org/wiki/Hoare_triple#Conditional_rule
>
> any language with an if/else construct has two postconditions
>
>     {B && P} S {Q}, {!B && P} T {Q}
>     ----
>     {P} if B then S else T endif {Q}

Only one postcondition here (namely Q).

>
> or mine
>
>     {B && P} S {Q}, {!B && P} T {R}
>     ----
>     {P} if B then S else T endif {Q || R}
>
> identical since "Q" -> "Q || R", "R" -> "Q || R", "Q || Q" -> "Q" are
> tautologies

Again, only one post condition here (namely Q || R).

And before you try to say that Q is one postcondition and R is the
other, consider that, in general, neither Q nor R are postconditions by
themselves.

Martin Shobe


Martin Shobe

[toc] | [prev] | [next] | [standalone]


#21754 — Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)

From"io_x" <a@b.c.invalid>
Date2012-06-03 17:30 +0200
SubjectRe: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)
Message-ID<4fcb81db$0$1389$4fafbaef@reader1.news.tin.it>
In reply to#21742
"io_x" <a@b.c.invalid> ha scritto nel messaggio 
news:4fcb2258$0$1375$4fafbaef@reader2.news.tin.it...
>
> "BartC" <bc@freeuk.com> ha scritto nel messaggio
> news:jqcjta$7mk$1@dont-email.me...
>> "mike3" <mike4ty4@yahoo.com> wrote in message
>> news:d4477aa8-f837-4bee-bb40-fbcc3da179c0@pr7g2000pbb.googlegroups.com...
>>> On May 29, 11:44 pm, mike3 <mike4...@yahoo.com> wrote:
>>> Djikstra!!!
>
> so Djikstra know what structured programming mean?

error above: "Dijkstra" excuse me... 

[toc] | [prev] | [next] | [standalone]


#21755 — Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)

FromJean-Christophe <5.d@free.fr>
Date2012-06-03 09:02 -0700
SubjectRe: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)
Message-ID<4699a394-fb6b-4fa4-8d6a-3eded9248d69@fr28g2000vbb.googlegroups.com>
In reply to#21754
On 3 juin, 17:30, "io_x" <a...@b.c.invalid> wrote:

> Dijkstra know what structured programming mean?

Edsgar Dijkstra is a quiche eater:
http://powerdown.free.fr/rp.html

[toc] | [prev] | [next] | [standalone]


#21768 — Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-06-03 22:37 +0100
SubjectRe: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)
Message-ID<0.3dc30416fd456756ba71.20120603223733BST.87mx4kcc0y.fsf@bsb.me.uk>
In reply to#21755
Jean-Christophe <5.d@free.fr> writes:

> On 3 juin, 17:30, "io_x" <a...@b.c.invalid> wrote:
>
>> Dijkstra know what structured programming mean?
>
> Edsgar Dijkstra is a quiche eater:
> http://powerdown.free.fr/rp.html

"Was", not "is".  He died in 2002.

To get a flavour of what a real "quiche eater" is like, read his
development of a program to find the convex hull of a set of 3D points,
which is done in parallel with the development of a proof of the
algorithm's correctness.[1]  In fact, read the whole book, if you have
time.  It changed the way I think about programming.

[1] E. W. Dijkstra, "A Discipline of Programming", Prentice Hall, 1977,
Chapter 24, pp 168--191.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#21794 — Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)

FromIke Naar <ike@iceland.freeshell.org>
Date2012-06-04 07:28 +0000
SubjectRe: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)
Message-ID<slrn3vfsjsoot6.6c9.ike@iceland.freeshell.org>
In reply to#21768
On 2012-06-03, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> Jean-Christophe <5.d@free.fr> writes:
>> Edsgar Dijkstra is a quiche eater:
>> http://powerdown.free.fr/rp.html
>
> "Was", not "is".  He died in 2002.
>
> To get a flavour of what a real "quiche eater" is like, read his
> development of a program to find the convex hull of a set of 3D points,
> which is done in parallel with the development of a proof of the
> algorithm's correctness.[1]  In fact, read the whole book, if you have
> time.  It changed the way I think about programming.
>
> [1] E. W. Dijkstra, "A Discipline of Programming", Prentice Hall, 1977,
> Chapter 24, pp 168--191.

Another book, that describes the same ideas in a more accessible manner,
is David Gries' "The Science of Programming", Springer, 1981.
With a foreword by E.W. Dijkstra.

[toc] | [prev] | [next] | [standalone]


#21945 — Re: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)

FromTim Rentsch <txr@alumni.caltech.edu>
Date2012-06-08 01:28 -0700
SubjectRe: GOTOs discovered in "real world" program! (was Re: Error returns and repeated code, GOTOs, etc.)
Message-ID<kfnzk8egqc3.fsf@x-alumni2.alumni.caltech.edu>
In reply to#21768
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Jean-Christophe <5.d@free.fr> writes:
>
>> On 3 juin, 17:30, "io_x" <a...@b.c.invalid> wrote:
>>
>>> Dijkstra know what structured programming mean?
>>
>> Edsgar Dijkstra is a quiche eater:
>> http://powerdown.free.fr/rp.html
>
> "Was", not "is".  He died in 2002.
>
> To get a flavour of what a real "quiche eater" is like, read his
> development of a program to find the convex hull of a set of 3D points,
> which is done in parallel with the development of a proof of the
> algorithm's correctness.[1]  In fact, read the whole book, if you have
> time.  It changed the way I think about programming.
>
> [1] E. W. Dijkstra, "A Discipline of Programming", Prentice Hall, 1977,
> Chapter 24, pp 168--191.

An excellent book!  A little difficult to read on
one's own, I think.  I was lucky enough to get it
almost direct from the horse's mouth, in a course
taught by Martin Rem (who had been one of Dijkstra's
doctoral students).  I count this as one of my three
main influences in program development.

[toc] | [prev] | [next] | [standalone]


#21889 — Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

Frommike3 <mike4ty4@yahoo.com>
Date2012-06-06 02:54 -0700
SubjectWhy was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<313ed2ec-dece-43f5-b2b3-1c5a63229add@t1g2000pbl.googlegroups.com>
In reply to#21611
On May 31, 5:39 pm, mike3 <mike4...@yahoo.com> wrote:
> On May 29, 11:44 pm, mike3 <mike4...@yahoo.com> wrote:
<snip>

I've been wondering about this. _Why_ was a GOTO used in this
program? How could one be used in _such a high-profile program
like that_? And it's not just a lone GOTO or a few here and there,
as I said, this program is infected with a serious case of GOTOitis...

[toc] | [prev] | [next] | [standalone]


#21899 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-06-06 13:14 +0100
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<0.c82e19170840b2237717.20120606131443BST.87bokwbpsc.fsf@bsb.me.uk>
In reply to#21889
mike3 <mike4ty4@yahoo.com> writes:

> On May 31, 5:39 pm, mike3 <mike4...@yahoo.com> wrote:
>> On May 29, 11:44 pm, mike3 <mike4...@yahoo.com> wrote:
> <snip>
>
> I've been wondering about this. _Why_ was a GOTO used in this
> program? How could one be used in _such a high-profile program
> like that_? And it's not just a lone GOTO or a few here and there,
> as I said, this program is infected with a serious case of GOTOitis...

You'd have to ask the people who wrote it.

Some of the code looks extraordinary to me.  Whilst the vast majority of
goto's are clearly of the "error cleanup" sort, they are not all like
that.  For example there is this pattern:

        cmsgp = CMSG_FIRSTHDR(msg);
        while (cmsgp != NULL) {
                socket_log(...);

#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
                if (...) {
                        /* stuff */
                        goto next;
                }
#endif

#ifdef SO_TIMESTAMP
                if (...) {
                        /* stuff */
                        goto next;
                }
#endif
        next:
                cmsgp = CMSG_NXTHDR(msg, cmsgp);
        }

Why is this not just a for loop?  Failing that, why not just remove the
label and the goto's?  Maybe this is a fossilised relic of some much
more complex code.

Although there may well be a reason the code ended up like this, I hope
everyone agrees that it would be odd (to say the least) to write it like
this from scratch.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#21905 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

Frompete <pfiland@mindspring.com>
Date2012-06-06 09:22 -0400
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<4FCF598A.463@mindspring.com>
In reply to#21899
Ben Bacarisse wrote:
> 
> mike3 <mike4ty4@yahoo.com> writes:
> 
> > On May 31, 5:39 pm, mike3 <mike4...@yahoo.com> wrote:
> >> On May 29, 11:44 pm, mike3 <mike4...@yahoo.com> wrote:
> > <snip>
> >
> > I've been wondering about this. _Why_ was a GOTO used in this
> > program? How could one be used in _such a high-profile program
> > like that_? And it's not just a lone GOTO or a few here and there,
> > as I said, this program is infected with a serious case of GOTOitis...
> 
> You'd have to ask the people who wrote it.
> 
> Some of the code looks extraordinary to me.  Whilst the vast majority of
> goto's are clearly of the "error cleanup" sort, they are not all like
> that.  For example there is this pattern:
> 
>         cmsgp = CMSG_FIRSTHDR(msg);
>         while (cmsgp != NULL) {
>                 socket_log(...);
> 
> #ifdef ISC_PLATFORM_HAVEIN6PKTINFO
>                 if (...) {
>                         /* stuff */
>                         goto next;
>                 }
> #endif
> 
> #ifdef SO_TIMESTAMP
>                 if (...) {
>                         /* stuff */
>                         goto next;
>                 }
> #endif
>         next:
>                 cmsgp = CMSG_NXTHDR(msg, cmsgp);
>         }
> 
> Why is this not just a for loop?
> Failing that, why not just remove the
> label and the goto's?  Maybe this is a fossilised relic of some much
> more complex code.
> 
> Although there may well be a reason
> the code ended up like this, I hope
> everyone agrees that it would be odd (to say the least)
> to write it like this from scratch.

It may be the case 
that it is, or was, somewhat common 
for expert proffesional programmers
to have accomplished a lot of proffesional programming work
before they became experts.

I recall many many years ago, 
showing some crappy looking code to my new boss,
and him telling me that because of time constraints
I would soon be writing crappy looking code too.
And he was right.
They hired me when they needed a programmer right away,
and I didn't know C or good writing style
nearly as well as I do now,
and because of time constraints, I had to program quickly.

-- 
pete

[toc] | [prev] | [next] | [standalone]


#21906 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

FromWillem <willem@toad.stack.nl>
Date2012-06-06 13:49 +0000
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<slrnjsuo04.2tcm.willem@toad.stack.nl>
In reply to#21905
pete wrote:
) I recall many many years ago, 
) showing some crappy looking code to my new boss,
) and him telling me that because of time constraints
) I would soon be writing crappy looking code too.
) And he was right.
) They hired me when they needed a programmer right away,
) and I didn't know C or good writing style
) nearly as well as I do now,
) and because of time constraints, I had to program quickly.

Your boss obviously was unaware that crappy code saves time in the
short run, but costs more time (with compound interest) in the long run.

But it seems that choosing short term benefits over long term benefits
is all the rage these days, so that is no surprise.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

[toc] | [prev] | [next] | [standalone]


#21908 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

FromRui Maciel <rui.maciel@gmail.com>
Date2012-06-06 14:56 +0100
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<jqnnir$7un$1@speranza.aioe.org>
In reply to#21906
Willem wrote:

> Your boss obviously was unaware that crappy code saves time in the
> short run, but costs more time (with compound interest) in the long run.
> 
> But it seems that choosing short term benefits over long term benefits
> is all the rage these days, so that is no surprise.

If someone is in the business of fixing problems, writing crappy code saves 
time in the short run and guarantees a bit of a cash flow in the long run.

http://dilbert.com/strips/comic/1995-11-13/


Rui Maciel

[toc] | [prev] | [next] | [standalone]


#21909 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-06-06 10:17 -0400
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<4FCF6695.3040806@verizon.net>
In reply to#21906
On 06/06/2012 09:49 AM, Willem wrote:
...
> But it seems that choosing short term benefits over long term benefits
> is all the rage these days, so that is no surprise.

"these days"? Has it ever not been so?

[toc] | [prev] | [next] | [standalone]


#21902 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

FromAngel <angel+news@spamcop.net>
Date2012-06-06 13:06 +0000
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<slrnjsulek.ecf.angel+news@pearlgates.net>
In reply to#21889
On 2012-06-06, mike3 <mike4ty4@yahoo.com> wrote:
> On May 31, 5:39 pm, mike3 <mike4...@yahoo.com> wrote:
>> On May 29, 11:44 pm, mike3 <mike4...@yahoo.com> wrote:
><snip>
>
> I've been wondering about this. _Why_ was a GOTO used in this
> program? How could one be used in _such a high-profile program
> like that_? And it's not just a lone GOTO or a few here and there,
> as I said, this program is infected with a serious case of GOTOitis...

A quick search through the source code of Linux 3.2.12 reveals no less
than 94422 goto statements.

I agree that one should think very carefully about using a goto statement
where structured code would be much better. But there are, especially in
exception handling (which, um, C doesn't really provide), cases where the
use of a goto statement produces much more elegant code.

There is an interesting read about it all here:
http://kerneltrap.org/node/553/2131


I agree with what Scott Robert Ladd states: Bad code is produced by bad
programmers, not by bad language features.


-- 
"C provides a programmer with more than enough rope to hang himself.
C++ provides a firing squad, blindfold and last cigarette."
- seen in comp.lang.c

[toc] | [prev] | [next] | [standalone]


#21937 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

Frommike3 <mike4ty4@yahoo.com>
Date2012-06-07 16:26 -0700
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<a00f6a5a-8ca9-4f1c-81c5-3618c4a5cf82@oe8g2000pbb.googlegroups.com>
In reply to#21902
On Jun 6, 7:06 am, Angel <angel+n...@spamcop.net> wrote:
> On 2012-06-06, mike3 <mike4...@yahoo.com> wrote:
>
> > On May 31, 5:39 pm, mike3 <mike4...@yahoo.com> wrote:
> >> On May 29, 11:44 pm, mike3 <mike4...@yahoo.com> wrote:
> ><snip>
>
> > I've been wondering about this. _Why_ was a GOTO used in this
> > program? How could one be used in _such a high-profile program
> > like that_? And it's not just a lone GOTO or a few here and there,
> > as I said, this program is infected with a serious case of GOTOitis...
>
> A quick search through the source code of Linux 3.2.12 reveals no less
> than 94422 goto statements.
>
> I agree that one should think very carefully about using a goto statement
> where structured code would be much better. But there are, especially in
> exception handling (which, um, C doesn't really provide), cases where the
> use of a goto statement produces much more elegant code.
>
> There is an interesting read about it all here:http://kerneltrap.org/node/553/2131
>
> I agree with what Scott Robert Ladd states: Bad code is produced by bad
> programmers, not by bad language features.
>

So would you say that using GOTO in the program I originally asked
about to
handle the errors would be an "acceptable use"?

[toc] | [prev] | [next] | [standalone]


#21957 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

FromAngel <angel+news@spamcop.net>
Date2012-06-08 14:26 +0000
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<slrnjt42sm.o4b.angel+news@pearlgates.net>
In reply to#21937
On 2012-06-07, mike3 <mike4ty4@yahoo.com> wrote:
> On Jun 6, 7:06?am, Angel <angel+n...@spamcop.net> wrote:
>> On 2012-06-06, mike3 <mike4...@yahoo.com> wrote:
>>
>> > On May 31, 5:39 pm, mike3 <mike4...@yahoo.com> wrote:
>> >> On May 29, 11:44 pm, mike3 <mike4...@yahoo.com> wrote:
>> ><snip>
>>
>> > I've been wondering about this. _Why_ was a GOTO used in this
>> > program? How could one be used in _such a high-profile program
>> > like that_? And it's not just a lone GOTO or a few here and there,
>> > as I said, this program is infected with a serious case of GOTOitis...
>>
>> A quick search through the source code of Linux 3.2.12 reveals no less
>> than 94422 goto statements.
>>
>> I agree that one should think very carefully about using a goto statement
>> where structured code would be much better. But there are, especially in
>> exception handling (which, um, C doesn't really provide), cases where the
>> use of a goto statement produces much more elegant code.
>>
>> There is an interesting read about it all here:
>> http://kerneltrap.org/node/553/2131
>>
>> I agree with what Scott Robert Ladd states: Bad code is produced by bad
>> programmers, not by bad language features.
>
> So would you say that using GOTO in the program I originally asked
> about to
> handle the errors would be an "acceptable use"?

Since I haven't looked at the original program you refer to, I cannot
say really. My only point here is that not all uses of goto are
automatically "evil", and that there are real-life situations where its
use is justified and leads to better code.


-- 
"C provides a programmer with more than enough rope to hang himself.
C++ provides a firing squad, blindfold and last cigarette."
- seen in comp.lang.c

[toc] | [prev] | [next] | [standalone]


#22023 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

Frommike3 <mike4ty4@yahoo.com>
Date2012-06-08 15:19 -0700
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<69250d7c-11b6-4fad-9594-224298f17b2d@t1g2000pbl.googlegroups.com>
In reply to#21957
On Jun 8, 8:26 am, Angel <angel+n...@spamcop.net> wrote:
> On 2012-06-07, mike3 <mike4...@yahoo.com> wrote:
<snip>
> > So would you say that using GOTO in the program I originally asked
> > about to
> > handle the errors would be an "acceptable use"?
>
> Since I haven't looked at the original program you refer to, I cannot
> say really. My only point here is that not all uses of goto are
> automatically "evil", and that there are real-life situations where its
> use is justified and leads to better code.
>

I was referring to the example I showed in my OP:

http://groups.google.com/group/comp.lang.c/msg/338e8ac90f710e5e?hl=en&dmode=source

[toc] | [prev] | [next] | [standalone]


#22029 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

FromAngel <angel+news@spamcop.net>
Date2012-06-08 23:32 +0000
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<slrnjt52s4.oij.angel+news@pearlgates.net>
In reply to#22023
On 2012-06-08, mike3 <mike4ty4@yahoo.com> wrote:
> On Jun 8, 8:26?am, Angel <angel+n...@spamcop.net> wrote:
>> On 2012-06-07, mike3 <mike4...@yahoo.com> wrote:
><snip>
>> > So would you say that using GOTO in the program I originally asked
>> > about to
>> > handle the errors would be an "acceptable use"?
>>
>> Since I haven't looked at the original program you refer to, I cannot
>> say really. My only point here is that not all uses of goto are
>> automatically "evil", and that there are real-life situations where its
>> use is justified and leads to better code.
>>
>
> I was referring to the example I showed in my OP:
>
> http://groups.google.com/group/comp.lang.c/msg/338e8ac90f710e5e?hl=en&
> dmode=source

Perhaps it's not for me to say, as I haven't programmed seriously in
years. But I think this is exactly the same argument that the Linux
kernel people made for their use of "goto". So no, I personally don't
think the use of "goto" is bad in your example.

C has many features that make those who love structured code cry. But
IMHO, it's not the language's duty to protect bad programmers from
themselves. It's a tool, and it's  up to the programmer how that tool
gets used.


-- 
"C provides a programmer with more than enough rope to hang himself.
C++ provides a firing squad, blindfold and last cigarette."
- seen in comp.lang.c

[toc] | [prev] | [next] | [standalone]


#22030 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

From"BartC" <bc@freeuk.com>
Date2012-06-09 01:14 +0100
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<jqu4js$ovs$1@dont-email.me>
In reply to#22023

"mike3" <mike4ty4@yahoo.com> wrote in message 
news:69250d7c-11b6-4fad-9594-224298f17b2d@t1g2000pbl.googlegroups.com...
> On Jun 8, 8:26 am, Angel <angel+n...@spamcop.net> wrote:
>> On 2012-06-07, mike3 <mike4...@yahoo.com> wrote:
> <snip>
>> > So would you say that using GOTO in the program I originally asked
>> > about to
>> > handle the errors would be an "acceptable use"?
>>
>> Since I haven't looked at the original program you refer to, I cannot
>> say really. My only point here is that not all uses of goto are
>> automatically "evil", and that there are real-life situations where its
>> use is justified and leads to better code.
>>
>
> I was referring to the example I showed in my OP:
>
> http://groups.google.com/group/comp.lang.c/msg/338e8ac90f710e5e?hl=en&dmode=source

If you take the function with the gotos, and simplify the structure, it 
looks like this:

    Init(a); if(x) goto f0;
    Init(b); if(x) goto f1;
    Init(c); if(x) goto f2;
    Init(d); if(x) goto f3;

    Set(b,3);  if(x) goto f4;

    Free(d); if(x) goto f3;
    Free(c); if(x) goto f2;
    Free(b); if(x) goto f1;
    Free(a); if(x) goto f0;
    return(p);

f4: Free(d);
f3: Free(c);
f2: Free(b);
f1: Free(a);
f0:
    return(q);

'x' is an error condition. In this form, you can see it is completely 
dominated by gotos. And not in a simple pattern either. In fact, I would say 
this qualifies as spaghetti code, even though all the gotos jump forward. 
This could almost be some 1970s Basic code!

And there's something not quite right about this code. But apart from 
anything else, there is a lot of repetition here: many lines almost 
identical to each other. Perhaps some sort of loop is called for.

Also notice that the first block of Free() is error-checked; the second 
block isn't; why not? Free(d) fails, you then Free(c), but don't seem to 
care if that is OK or not. In that case, why bother checking the first lot? 
Again, the two blocks do almost the same thing. (Imagine 26 variables 
instead of 4, then it's clear this approach doesn't scale well.)

Even in this abbreviated form, with only four variables, and a single-line 
main body, it's difficult to see what needs freeing, and what doesn't. This 
has been discussed before: it's easier to arrange things so that you can 
free an object unconditionally.

Or perhaps make use of variable-argument functions (I've never used them 
myself), then you can have:

rv=MultiInit(a,b,c,d,...)   /* stops at first error */

rv=MultiFree(a,b,c,d,....); /* returns first error, but frees the rest */

-- 
Bartc 

[toc] | [prev] | [next] | [standalone]


#22059 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

FromJean-Christophe <5.d@free.fr>
Date2012-06-09 04:36 -0700
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<ada7d611-b69f-48d5-9cb1-4ceda2724120@x21g2000vbc.googlegroups.com>
In reply to#22030
On 9 juin, 02:14, "BartC" :

> (...) Or perhaps make use of variable-argument functions
> (I've never used them myself), then you can have:
> rv=MultiInit(a,b,c,d,...)   /* stops at first error */
> rv=MultiFree(a,b,c,d,....); /* returns first error, but frees the rest */

Still, if there are a lot of parameters (aa,ab,ac,...,zz)
then wouldn't it be better to init/free by using a loop ?
Assuming that a,b,c are different types of data structures,
it would make sense to use some struct to implement a void* pointer
to the data structures and pointers to their init/free functions,
initializing data w/ their pointers in a loop and stop at first error,
free data in a loop : don't need any goto, makes code shorter and more
clear.

[toc] | [prev] | [next] | [standalone]


#22061 — Re: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)

FromMalcolm McLean <malcolm.mclean5@btinternet.com>
Date2012-06-09 05:54 -0700
SubjectRe: Why was there a GOTO? (was Re: GOTOs discovered in "real world" program!)
Message-ID<538a3102-833f-4a0b-a790-733cc91629fa@googlegroups.com>
In reply to#22030
בתאריך יום שבת, 9 ביוני 2012 01:14:43 UTC+1, מאת Bart:
> 
> If you take the function with the gotos, and simplify the structure, it 
> looks like this:
> 
>     Init(a); if(x) goto f0;
>     Init(b); if(x) goto f1;
>     Init(c); if(x) goto f2;
>     Init(d); if(x) goto f3;
> 
>     Set(b,3);  if(x) goto f4;
> 
>     Free(d); if(x) goto f3;
>     Free(c); if(x) goto f2;
>     Free(b); if(x) goto f1;
>     Free(a); if(x) goto f0;
>     return(p);
> 
> f4: Free(d);
> f3: Free(c);
> f2: Free(b);
> f1: Free(a);
> f0:
>     return(q);
> 
> 'x' is an error condition. In this form, you can see it is completely 
> dominated by gotos. And not in a simple pattern either. In fact, I would say 
> this qualifies as spaghetti code, 
>
The central mistake is that the the consturctor takes an empty structure to fill in, rather than returning a pointer to an allocated structure. Then the destructor itself can return an error.
Change this, and you get

     Init(a); if(x) goto f0;
     Init(b); if(x) goto f0;
     Init(c); if(x) goto f0;
     Init(d); if(x) goto f0;
 
     Set(b,3);  if(x) goto f0;
 
     Free(d); 
     Free(c); 
     Free(b); 
     Free(a);
     return(p);
 
 f0: Free(d);
     Free(c);
     Free(b);
     Free(a);
     return(q);

That's much mpre acceptable. The control flow is still doiminated by gotos, but that's because all the calls can return errors, which go into a single error handler.

 

[toc] | [prev] | [next] | [standalone]


Page 5 of 7 — ← Prev page 1 2 3 4 [5] 6 7  Next page →

Back to top | Article view | comp.lang.c


csiph-web