簡體   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