>>>> If you're willing to assume you're using gcc,
>>> We're not.
>> That's what I'd expect - but the message I was responding to seemed
>> to be entirely predicated upon that, [...]
> My fault for the misunderstanding, and I wouldn't suggest for a
> minute that PCB / gEDA should become gcc only.

Well, it's also entirely possible I'm at least as much to blame as you
are; it wouldn't be the first time I read something that wasn't
actually there into text.

> I am interested in your examples though..

Here's a really simple example which does a recursive tree walk,
throwing out to the top level if a node with a particular property is
found.  Obviously, there are lots of ways to do this particular task;
this technique is most useful when the tree walk is more complicated
than this (and possibly off in another file, or part of a library
package, or some such).

void walk_tree(TREE *t, void (*fn)(TREE *))
{
 int i;

 (*fn)(t);
 for (i=t->nchildren-1;i>=0;i--) walk_tree(t->children[i]);
}

int tree_has_interesting_node(TREE *t, int (*interest)(TREE *))
{
 __label__ found;

 void check_node(TREE *n)
  { if ((*interest)(n)) goto found; /* "throw" */
  }

 walk_tree(t,&check_node);
 return(0);
found:; /* "catch" */
 return(1);
}

This, of course, is a toy demo example.  For some real examples, look
at stuff in my FTP server, ftp.rodents-montreal.org.  Specifically:

/mouse/hacks/pnmtartan.c - all three gotos in this program are throws.

/mouseware/local-src/halign/halign-20080930/halign.c - the "goto retc"
is a throw.

/mouseware/moussh/moussh-20080703/ - for good examples here, see
agent-server.c, which uses this technique to throw out of a parser in
case of an error, or various functions, such as hk_ssh_dss_checksig in
alg-hk-ssh-dss.c, or rem_chanreq in client.c, which use this to throw
out of parse_data in case of error.  One of the best examples is
config.s, another case of throwing out of a parser in case of error
(see cferr_throw inside load_config).

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML                [EMAIL PROTECTED]
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


_______________________________________________
geda-dev mailing list
[email protected]
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev

Reply via email to