What do DECLSPEC and SDLCALL mean in function definitions in the Linux header file?

I poked the SDL 2 header files and found that most of the functions I came across had the following form:

extern DECLSPEC int SDLCALL SDL_FunctionName();

I understand the meaning extern, intand SDL_FunctionName(storage class specifier, the return value of the function name, respectively). However, I must admit that I had not seen such DECLSPECand before SDLCALL. Searches for the former simply provide the Win32 / 64 API, and nothing good is appropriate for the latter.

What do these two things mean and what do they do?

+4
source share
5 answers

, () C/++.

DECLSPEC - , C/++. __declspec(dllexport), __declspec(dllimport) , . . .

  • / DECLSPEC __declspec(dllexport). - DLL. ( ), - DLL. . .

  • , DECLSPEC __declspec(dllimport). , , , thunks. . .

SDLCALL , . , __stdcall, __cdecl .. .

, , . , SDK, , .

+4

SDLCALL

SDLCALL , . , ( ) .

MSDN .

DECLSPEC

, . Windows DLL.

+2

SDL, begin_code.h, , DECLSPEC:

/* Some compilers use a special export keyword */
#ifndef DECLSPEC
# if defined(__WIN32__) || defined(__WINRT__)
#  ifdef __BORLANDC__
#   ifdef BUILD_SDL
#    define DECLSPEC
#   else
#    define DECLSPEC    __declspec(dllimport)
#   endif
#  else
#   define DECLSPEC __declspec(dllexport)
#  endif
# else
#  if defined(__GNUC__) && __GNUC__ >= 4
#   define DECLSPEC __attribute__ ((visibility("default")))
#  elif defined(__GNUC__) && __GNUC__ >= 2
#   define DECLSPEC __declspec(dllexport)
#  else
#   define DECLSPEC
#  endif
# endif
#endif

SDLCALL:

/* By default SDL uses the C calling convention */
#ifndef SDLCALL
#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
#define SDLCALL __cdecl
#else
#define SDLCALL
#endif
#endif /* SDLCALL */

, Linux, DECLSPEC :

__attribute__ ((visibility("default")))

__declspec(dllexport)

GCC SDLCALL .

, .

+1

GCC wiki . http://gcc.gnu.org/wiki/Visibility

( ), , . Linux ( ) , , . , , .

- GCC ++, , C.

DECLSPEC. Linux SDLCALL , , , , C-.

+1
source

They are preprocessor definitions. They are used to create a cross platform because Windows requires DLL modifiers. When a library is created as a DLL in Windows, it is defined as __declspec(dllexport), therefore, the function is externally visible. When headers are used by an application associated with a DLL in Windows, it is defined as __declspec(dllimport), therefore, the compiler knows to look for it in an external DLL. See Source Code here for how they are defined.

0
source

Source: https://habr.com/ru/post/1540462/


All Articles