This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC 4.7.0RC: Mangled names in cc1


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]