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 ????
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With