What dialect c can allow GCC to compile some kind of fun (...)?

To compile some old Ac code that has a function prototype

void somefun(...) 

gcc 4.1.2 always report an error

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

But I can’t change the code, so which version of the C-set should I use for GCC to compile this code?

 gcc -c Ac ???? 
+6
source share
2 answers

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

Then you should declare it in C using void somefun() (K & R style).

This will also require binding to g++ .

If the C ++ link is not what you want, then you must change the function to not accept arguments and declare it in the K & R style.

+3
source

I no longer think this is possible. See the Comment in this (3,0,0 - pretty 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 do not have the ability to accept this 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); 
+4
source

Source: https://habr.com/ru/post/893448/


All Articles