0

I have come across this code in the source of 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); } 

Why is ZEXPORT used in the function, and how does it even compile?

If I change ZEXPORT to a random integer, like 5:

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

code won't even compile anymore.

Here are possible expansions:

define ZEXPORT WINAPI define ZEXPORT __declspec(dllexport) 
6
  • What does ZEXPORT expand to? Commented Apr 1, 2020 at 19:11
  • 3
    How does zlib.h (which is #included in your link) #define ZEXPORT? It is unlikely to be #define ZEXPORT 5 Commented Apr 1, 2020 at 19:11
  • Add more info above. Commented Apr 1, 2020 at 19:15
  • So, it depends on the environment. Commented Apr 1, 2020 at 19:16
  • ZEXPORT is defined in zconf.h to a compiler-specific way to "export" functions. Commented Apr 1, 2020 at 19:16

1 Answer 1

2

If Windows is used, this macro compiles to:

WINAPI 

This is another macro that most likely expands to:

__stdcall 

This makes the Microsoft compiler use a calling convention where the callee (rather than the caller) cleans up the stack.

On BEOS, this is defined to either:

__declspec(dllimport) 

or:

__declspec(dllexport) 

depending on whether the header file is being used in a user application or the library itself, respectively.

If any other operating system other than Windows or BEOS is used, then this macro is defined to nothing.

Sign up to request clarification or add additional context in comments.

Comments