iowin32.h 中的 OF 宏 [英] OF macro in iowin32.h

查看:18
本文介绍了iowin32.h 中的 OF 宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解 minizip 的 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));

(来源,过时但仍然相关)

OF 宏有什么作用?

推荐答案

名称 OF 可能是 Old function declaration 的缩写.

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

在 80 年代甚至更早的旧时代,此函数的典型声明如下所示:

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

fill_win32_filefunc();

就是这样.没有明确的返回类型,没有声明的参数.返回类型默认为 int,参数无关紧要,因为调用者(希望)无论如何都会传入正确数据类型的值.

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.

后来的版本引入了 void 类型,所以声明可能是这样的:

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

void fill_win32_filefunc();

而当ANSI C89出来时,它引入了函数参数的声明.现在一个好的声明看起来像这样:

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);

在 1989 年之后的早期,有很多代码需要将两种风格结合起来.因此,发明了宏 OF(或有时 _P 或其他名称).它的定义通常是:

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.

如今,除了非常非常旧的编译器之外,不再需要这种 hack.

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

这篇关于iowin32.h 中的 OF 宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆