This is the mail archive of the 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


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++.



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