OF macro in iowin32.h

前端 未结 1 1285
走了就别回头了
走了就别回头了 2021-01-04 20:26

I can\'t understand the following line from minizip\'s iowin32.h:

void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));

(Sour

相关标签:
1条回答
  • 2021-01-04 20:41

    The name OF might be an abbreviation for Old function declaration.

    In the old times of the 80s and even earlier, a typical declaration for this function looked like this:

    fill_win32_filefunc();
    

    That's it. No explicit return type, no declared parameters. The return type is int by default, and the parameters don't matter, since the caller will (hopefully) pass in the values of the right data types anyway.

    Later versions introduced the void type, so the declaration could look like this:

    void fill_win32_filefunc();
    

    And when ANSI C89 came out, it introduced the declaration of function parameters. Now a good declaration looked like this:

    void fill_win32_filefunc(zlib_filefunc_def* pzlib_filefunc_def);
    

    In the time early after 1989, there was a lot of code that needed to combine the two styles. Therefore a macro OF (or sometimes _P or of another name) was invented. Its definition is usually:

    #if PRE_ANSI_C89
    #  define OF(args) ()
    #else
    #  define OF(args) args
    #endif
    

    From that, both versions are generated easily.

    Nowadays, this hack is not needed anymore, except for very very old compilers.

    0 讨论(0)
提交回复
热议问题