[cfe-dev] clang comparison webpage

Mouse mouse at Rodents-Montreal.ORG
Mon Dec 9 12:04:27 PST 2013

> So back when I investigated this a few years ago, it turned out a lot
> of people asking for nested functions were in fact just using them as
> syntactic sugar to get local scoping for things like unit tests in C.

> We could avoid most of the unpleasant stuff if we restrict support to
> direct calling as I think the trampolines are only needed to take the
> address as a function pointer.


> Ditto cross-function goto with local labels.

Yes; they are hard only when control passes outside the outermost scope
involved, in between setup and goto.

> Mouse, would this "safe" but limited implementation of nested
> functions meet your use-case?

Some but definitely not all of them.  Some of them are cases like
wanting a recursive function which references lexically local things
like function arguments; those would be fine with such an
implementation.  But some of my use cases are, basically, currying,
things like turning a three-argument "compare X and Y with context Z"
function into something that can be passed to an external API like
qsort.  And some are essentially "better longjmp" things like

 __label__ out;

 void throw_out(void)
  { goto out;

 if (0)
    ...maybe do a little cleanup...
 errthrow = &throw_out; /* errthrow is file- or program-global */
 /* or */
 something(...,&throw_out); /* last arg is called to abort processing */

(one of the two real uses I've found for "if (0)").

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse at rodents-montreal.org
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

More information about the cfe-dev mailing list