繁体   English   中英

在 C 中的函数声明中使用宏

[英]Using a macro in function declaration in C

我在CMake的源代码中遇到过这段代码:

https://fossies.org/windows/misc/cmake-3.17.0.zip/cmake-3.17.0/Utilities/cmzlib/compress.c

int ZEXPORT compress (dest, destLen, source, sourceLen)
  Bytef *dest;
  uLongf *destLen;
  const Bytef *source;
  uLong sourceLen;
{
  return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
}

为什么在函数中使用ZEXPORT ,它是如何编译的?

如果我将ZEXPORT更改为随机整数,例如5

int 5 compress (dest, destLen, source, sourceLen)

代码甚至不再编译。

以下是可能的扩展:

define ZEXPORT WINAPI
define ZEXPORT   __declspec(dllexport)

如果使用 Windows,则此宏编译为:

WINAPI

这是另一个最有可能扩展为:

__stdcall

这使得 Microsoft 编译器使用调用约定,其中被调用者(而不是调用者)清理堆栈。

在 BEOS 上,这被定义为:

__declspec(dllimport)

或者:

__declspec(dllexport)

分别取决于头文件是在用户应用程序中使用还是在库本身中使用。

如果使用 Windows 或 BEOS 以外的任何其他操作系统,则该宏定义为空。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM