哪种c语言可以让GCC编译一些fun(...)?

发布于 2024-11-26 03:46:46 字数 266 浏览 1 评论 0原文

编译一些遗留代码 Ac ,它有一个函数原型

void somefun(...)

gcc 4.1.2 总是报错

 error: ISO C requires a named argument before ...

但我无法修改代码,那么我应该使用什么 C dialet 选项让 GCC 编译这段代码?

gcc -c A.c ????

To compile some legacy code A.c , which has a function prototype

void somefun(...)

gcc 4.1.2 always tell an error

 error: ISO C requires a named argument before ...

But I can not modify the code, so what C dialet option should I use to let GCC compile this code?

gcc -c A.c ????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花想c 2024-12-03 03:46:46

我认为这不再可能了。请参阅此(3.4.0 - 已经很旧)GCC源c-parse.in

/* This is what appears inside the parens in a function declarator.
   Is value is represented in the format that grokdeclarator expects.  */
parmlist_2:  /* empty */
        { $ = get_parm_info (0); }
    | ELLIPSIS
        { $ = get_parm_info (0);
          /* Gcc used to allow this as an extension.  However, it does
             not work for all targets, and thus has been disabled.
             Also, since func (...) and func () are indistinguishable,
             it caused problems with the code in expand_builtin which
             tries to verify that BUILT_IN_NEXT_ARG is being used
             correctly.  */
          error ("ISO C requires a named argument before `...'");

GCC 2.95.3 有相同的评论。

较新版本的 GCC (4.6.1) 也没有看到接受该代码的选项(来自 gcc/c-parse.c):

static struct c_arg_info *
c_parser_parms_list_declarator (c_parser *parser, tree attrs)
{
...
  if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
    {
      struct c_arg_info *ret = build_arg_info ();
      /* Suppress -Wold-style-definition for this case.  */
      ret->types = error_mark_node;
      error_at (c_parser_peek_token (parser)->location,
        "ISO C requires a named argument before %<...%>");
      c_parser_consume_token (parser);

I don't think that possible anymore. See the comment in this (3.4.0 - quite old already) GCC source c-parse.in:

/* This is what appears inside the parens in a function declarator.
   Is value is represented in the format that grokdeclarator expects.  */
parmlist_2:  /* empty */
        { $ = get_parm_info (0); }
    | ELLIPSIS
        { $ = get_parm_info (0);
          /* Gcc used to allow this as an extension.  However, it does
             not work for all targets, and thus has been disabled.
             Also, since func (...) and func () are indistinguishable,
             it caused problems with the code in expand_builtin which
             tries to verify that BUILT_IN_NEXT_ARG is being used
             correctly.  */
          error ("ISO C requires a named argument before `...'");

GCC 2.95.3 has the same comment.

Newer versions of GCC (4.6.1) also don't see to have an option to accept that code (from gcc/c-parse.c):

static struct c_arg_info *
c_parser_parms_list_declarator (c_parser *parser, tree attrs)
{
...
  if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
    {
      struct c_arg_info *ret = build_arg_info ();
      /* Suppress -Wold-style-definition for this case.  */
      ret->types = error_mark_node;
      error_at (c_parser_peek_token (parser)->location,
        "ISO C requires a named argument before %<...%>");
      c_parser_consume_token (parser);
咆哮 2024-12-03 03:46:46

我认为 GCC 中的任何 C 方言都不接受这一点,但 G++ 接受。您可以做的是将函数定义放在 extern "C" {} 块中,并使用 g++ 编译包含它的模块(假设它也是一个有效的 C++ 函数)。

然后,您必须在 C 中使用 void somefun() 声明它(K&R 风格)。

不过,这也需要与 g++ 链接。

如果 C++ 链接不是您想要的,那么您应该将该函数更改为不带参数并以 K&R 风格声明它。

I don't think any of the C dialects in GCC accept this, but G++ does. What you can do is put the function definition in an extern "C" {} block and compile the module containing it with g++ (assuming it's also a valid C++ function).

You must then declare it in C with void somefun() (K&R style).

This will require linking with g++ as well, though.

If C++ linkage is not what you want, then you should change the function to take no arguments and declare it in K&R style.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文