简体   繁体   English

C ++中类定义前面的宏

[英]macro in front of class definition in c++

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? 谁能解释下面的类声明前面的宏术语(以下代码中的术语OPENRTI_LOCAL)做什么? Please ignore the context of the following example. 请忽略以下示例的上下文。 I am looking for a general explanation of the following type of cpp class declaration. 我正在寻找以下cpp类声明类型的一般解释。

namespace OpenRTI {
  class OPENRTI_LOCAL RTI1516ETestAmbassador : public RTITest::Ambassador, 
  public rti1516e::FederateAmbassador {
  ......
  }
}

This is a library-specific term that you'd need to look up in the OpenRTI library. 这是一个特定于库的术语,您需要在OpenRTI库中查找。 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. 通常,此位置可能有一个指定符,例如标准alignas ,因此宏可能会扩展到这样的指定符或特定于供应商的属性,或者仅扩展为空字符串。

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: 检查OpenRTI的源代码 ,看起来它只是表明简单代码在编译为共享库时被隐藏了:

// 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: OPENRTI_HELPER_DLL_LOCAL是:

// 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM