C function syntax, parameter types declared after parameter list

前端 未结 7 795
一个人的身影
一个人的身影 2020-11-22 12:34

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 e

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 13:04

    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.

提交回复
热议问题