Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OF macro in iowin32.h

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

void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));

(Source, outdated but still relevant)

What does the OF macro do?

like image 410
Natan Yellin Avatar asked Sep 04 '11 12:09

Natan Yellin


1 Answers

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.

like image 125
Roland Illig Avatar answered Oct 12 '22 12:10

Roland Illig