Reputation: 335
I am looking at this code passed onto me to resolve an issue but I have trouble understanding one of the function's definition.
void DESC_API ApplDesc(DescMsg* pMsg)
I can see that the function isnt returning anything so the void
holds good. But what is the DESC_API
doing in here? This is how it is defined in the header file
#if defined(DESC_API)
#else
/* No paging used. */
#define DESC_API
#endif
Upvotes: 0
Views: 88
Reputation: 6687
Looks like DESC_API
a is visibility macro. It might be defined to __declspec(dllexport)
or to __declspec(dllimport)
for MSVC or to __attribute__ ((visibility ("default")))
for gcc or clang.
Of course, it might be defined to something else (as said bellow), but the most popular use case is just symbols visibility attributes.
Since gcc and clang export all symbols by default, no attributes is needed and DESC_API
is blank. As for MSVC, your build system might set it via /DDESC_API=__declspec(dllimport)
externally.
Upvotes: 3
Reputation: 181714
The macro appears to be a hook by which additional qualifiers can be injected into function signatures. I'm inclined to think that its intended usage is to leverage compiler-specific extensions under certain circumstances, such as to mark functions as using some particular calling convention.
Note that the macro definition you present is conditional. It provides for the macro to be defined (with empty replacement text) in the event that it is not already defined, where a previous definition might come from another header or from a command-line option.
Upvotes: 1
Reputation: 727037
It looks like DESC_API
could be used to switch between a function returning nothing and a function returning a void*
.
If you define
#define DESC_API *
the function would be returning a void pointer; otherwise, the function would return nothing.
Of course the rest of the function must follow through with a conditional return based on the value of DESC_API
.
Upvotes: 1
Reputation: 848
Well, probably does nothing, as you can see by the macro the DESC_API is replaced by blank, hence this is probably a macro used for readability convenience that's it though
Upvotes: 0