C function syntax, parameter types declared after

2018-12-31 16:51发布

I'm relatively new to C. I've come across a form of function syntax I've never seen before, where the parameter types are defined after that parameter list. Can someone explain to me how it is different than the typical C function syntax?

Example:

int main (argc, argv)
int argc;
char *argv[];
{
return(0);
}

7条回答
余欢
2楼-- · 2018-12-31 17:29

Old or not, I would argue what is old and what nat.. like the pyramids are ancient, but none of todays so called scientist have a clue how they where made. Looking back, old programs still work today without memory leaks, but these "new" programs tend to fail more then often. I see a trend here.

Probably they saw functions as structs which have a executable body. Knowledge of ASM is needed here to solve the mystery.

Edit, found a macro which indicates you do not need to supply argument names at all.

#ifndef OF /* function prototypes */
#  ifdef STDC
#    define OF(args)  args
#  else
#    define OF(args)  ()
#  endif
#endif

#ifndef Z_ARG /* function prototypes for stdarg */
#  if defined(STDC) || defined(Z_HAVE_STDARG_H)
#    define Z_ARG(args)  args
#  else
#    define Z_ARG(args)  ()
#  endif
#endif

Here is an usage example, library is zlib-1.2.11.

ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));

So my second guess would be for function overloading, otherwise these arguments had no use. One concrete function, and now infinite amount of functions with same name.

查看更多
登录 后发表回答