问题
can anyone explain what does the macro term in front of the following class declaration do (the term OPENRTI_LOCAL in the following code) do? Please ignore the context of the following example. I am looking for a general explanation of the following type of cpp class declaration.
namespace OpenRTI {
class OPENRTI_LOCAL RTI1516ETestAmbassador : public RTITest::Ambassador,
public rti1516e::FederateAmbassador {
......
}
}
回答1:
Checking OpenRTI's source code, it looks like it is simply indicating that the simply is meant to be hidden when compiled as a shared library:
// Now we use the generic helper definitions above to define OPENRTI_API and OPENRTI_LOCAL.
// OPENRTI_LOCAL is used for non-api symbols.
#ifdef OPENRTI_DLL // defined if OPENRTI is compiled as a DLL
# define OPENRTI_LOCAL OPENRTI_HELPER_DLL_LOCAL
#else // OPENRTI_DLL is not defined: this means OPENRTI is a static lib.
# define OPENRTI_LOCAL
#endif // OPENRTI_DLL
And OPENRTI_HELPER_DLL_LOCAL
is:
// Generic helper definitions for shared library support
#if defined _WIN32 || defined __CYGWIN__
# define OPENRTI_HELPER_DLL_LOCAL
#elif defined __GNUC__ && (4 <= __GNUC__)
# define OPENRTI_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden")))
#elif defined __SUNPRO_C && (0x550 <= __SUNPRO_C)
# define OPENRTI_HELPER_DLL_LOCAL __hidden
#else
# define OPENRTI_HELPER_DLL_LOCAL
#endif
回答2:
This is a library-specific term that you'd need to look up in the OpenRTI library. In general, there could be a specifier in this position such as the standard alignas, so the macro might expand to such a specifier or a vendor-specific attribute or just to an empty string.
来源:https://stackoverflow.com/questions/53144971/macro-in-front-of-class-definition-in-c