Hello,

For the interested reader, I eventually solved the nested function issue
by using either nested functions or C++11 lambdas, depending on whether
g++ is being used [0].

This is abstracted away by these (surprisingly not-too-ugly) macros to
define a local function, and declare a function parameter:

  #ifdef __cplusplus

  /* G++ doesn't implement nested functions, so use C++11 lambdas instead.  */

  # include <functional>

  # define local_define(ret, name, parms)     auto name = [=]parms
  # define function_parm(ret, name, parms)    std::function<ret parms> name

  #else  /* !__cplusplus */

  /* GNU C nested functions.  */

  # define local_define(ret, name, parms)     ret name parms
  # define function_parm(ret, name, parms)    ret (*name) parms

  #endif /* !__cplusplus */

They are used like this:

  static tree
  map (function_parm (tree, func, (const_tree)), tree t)
  {
    [...]
  }

  static tree
  foo (tree lst, tree y)
  {
    local_define (tree, frob, (const_tree x))
    {
      return do_something (x, y);
    };

    return map (frob, lst);
  }

Then there were other subtleties to work around, such as the lack of
support for designated initializers in g++.

Thanks,
Ludo’.

[0] 
https://gforge.inria.fr/scm/viewvc.php/trunk/gcc-plugin/src/starpu.c?root=starpu&r1=6225&r2=6226

Reply via email to