This is the mail archive of the
mailing list for the elfutils project.
Re: [PATCH] For clang use Blocks instead of nested functions.
- From: Petr Machata <pmachata at gmail dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Fri, 11 Sep 2015 13:08:00 +0200
- Subject: Re: [PATCH] For clang use Blocks instead of nested functions.
2015-09-05 1:54 GMT+02:00 Chih-Hung Hsieh <firstname.lastname@example.org>:
> * 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
> 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
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.