2015-09-05 1:54 GMT+02:00 Chih-Hung Hsieh <chh(a)google.com>:
* Clang has Blocks like closures that can serve similar
purpose as the nested functions in gnu99.
Syntax of Blocks is similar to nested functions that
*NESTED_FUNC macro can be used for the function/block
declarations.
See spec in
http://clang.llvm.org/docs/BlockLanguageSpec.html
* Local variables used in a closure should have __BLOCK
attribute unless they are constants.
* Formal parameters used in a closure should be copied
to local variable and declared as __BLOCK.
* Cannot goto and jump over __BLOCK variables, so these
variables have been moved to be declared before goto.
* Clang Blocks cannot copy an array to a closure,
and gcc complains about unbounded stack usage from alloca.
It seems to me cleaner to just wean elfutils off nested functions altogether.
Having a custom syntax to bridge the differences between LLVM and GCC
seems over the top. It introduces a layer of indirection that is not
familiar to C coders, and the usage mode is not immediately obvious
(viz the __BLOCK annotations). It's also fragile--people will forget
how to use this and that it's supposed to be used at all, so __BLOCK
annotations and variable ordering will go out of sync with
requirements.
Admittedly it's more work, as each use has to be attended to
separately, deciding whether a macro or a static function is more
appropriate to express the idea. Where (if) the nested functions are
used as callbacks, that can have ripple effects to other interfaces as
we need to pass extra context parameters. So there's that.
But ultimately that's the way to go if we want to have a portable codebase.
Thanks,
Petr