__declspec 官方文档翻译

Microsoft Specific 微软特有
  • The extended attribute syntax for specifying storage-class information uses the __declspec keyword, which specifies that an instance of a given type is to be stored with a Microsoft-specific storage-class attribute listed below. Examples of other storage-class modifiers include the static and extern keywords. However, these keywords are part of the ANSI specification of the C and C++ languages, and as such are not covered by extended attribute syntax. The extended attribute syntax simplifies and standardizes Microsoft-specific extensions to the C and C++ languages.
  • 译:使用__declspec关键字用于指定存储类信息的扩展属性语法。该关键字指定一个给定类型的实例将与下面列出的Microsoft特有的一个存储类属性一起存储。其他存储类修饰符的例子包括static和extern关键字。但是这些关键字是C和C++语言的ANSI规范的一部分,因此扩展属性语法未涵盖这些关键字。扩展属性语法简化并标准化了Microsoft特有的C和C++语言扩展。
Grammar 语法
  • decl-specifier:

    • __declspec ( extended-decl-modifier-seq )
  • extended-decl-modifier-seq:

    • extended-decl-modifier opt
    • extended-decl-modifier
    • extended-decl-modifier-seq
  • extended-decl-modifier:

    • align( # )
    • allocate(" segname ")
    • allocator
    • appdomain
    • code_seg(" segname ")
    • deprecated
    • dllimport
    • dllexport
    • jitintrinsic
    • naked
    • noalias
    • noinline
    • noreturn
    • nothrow
    • novtable
    • process
    • property( { get=get_func_name | ,put=put_func_name } )
    • restrict
    • safebuffers
    • selectany
    • spectre(nomitigation)
    • thread
    • uuid(" ComObjectGUID ")
  • White space separates the declaration modifier sequence. Examples appear in later sections.

  • 译:空格分隔开声明修饰符序列。后续有示例。

  • Extended attribute grammar supports these Microsoft-specific storage-class attributes: align, allocate, allocator, appdomain, code_seg, deprecated, dllexport, dllimport, jitintrinsic, naked, noalias, noinline, noreturn, nothrow, novtable, process, restrict, safebuffers, selectany, spectre, and thread. It also supports these COM-object attributes: property and uuid.

  • 译:扩展属性语法支持这些Microsoft特有的存储类属性:align, allocate, allocator, appdomain, code_seg, deprecated, dllexport, dllimport, jitintrinsic, naked, noalias, noinline, noreturn, nothrow, novtable, process, restrict, safebuffers, selectany, spectre, and thread。也支持以下COM对象属性:property 和uuid。

  • The code_seg, dllexport, dllimport, naked, noalias, nothrow, property, restrict, selectany, thread, and uuid storage-class attributes are properties only of the declaration of the object or function to which they are applied. The thread attribute affects data and objects only. The naked and spectre attributes affect functions only. The dllimport and dllexport attributes affect functions, data, and objects. The property, selectany, and uuid attributes affect COM objects.

  • 译:存储类属性code_seg, dllexport, dllimport, naked, noalias, nothrow, property, restrict, selectany, thread, and uuid仅是应用它们的对象或函数声明的属性。thread属性仅影响数据和对象。naked和spectre属性仅影响函数。dllimport和dllexport影响函数、数据和对象。selectany和uuid影响COM对象。

  • For compatibility with previous versions, _declspec is a synonym for __declspec unless compiler option /Za (Disable language extensions) is specified.

  • 译:为了兼容以前版本,除非指定编译选项/Za(禁用语言扩展),否则_declspec是__declspec同义词。

  • The __declspec keywords should be placed at the beginning of a simple declaration. The compiler ignores, without warning, any __declspec keywords placed after * or & and in front of the variable identifier in a declaration.

  • 译:__declspec关键字应该放在一个简单声明的开头。如果放在*或&之后以及声明中变量标识符前面,编译器会不警告忽略。

  • A __declspec attribute specified in the beginning of a user-defined type declaration applies to the variable of that type. For example:

  • 译:在用户自定义类型声明前指定的__declspec属性应用于该类型的变量,举例:

__declspec(dllimport) class X {} varX;
  • A __declspec attribute placed after the class or struct keyword applies to the user-defined type. For example:
  • 译:在class或struct关键字后放置的__declspec属性应用于该自定义类型,举例:
class __declspec(dllimport) X {};
  • The general guideline for using the __declspec attribute for simple declarations is as follows:
  • 译:将__declspec属性用于简单声明的一般准则如下:
decl-specifier-seq init-declarator-list;
  • The decl-specifier-seq should contain, among other things, a base type (e.g. int, float, a typedef, or a class name), a storage class (e.g. static, extern), or the __declspec extension. The init-declarator-list should contain, among other things, the pointer part of declarations. For example:
  • 译:除其他外,decl-specifier-seq应该包含一个基本类型(例如int, float, 一个 typedef, 或一个class名称),一个存储类(例如static,extern)或者一个__declspec扩展。 除其他外,init-declarator-list应该包含声明的指针部分,举例:
__declspec(selectany) int * pi1 = 0;   //Recommended, selectany & int both part of decl-specifier
int __declspec(selectany) * pi2 = 0;   //OK, selectany & int both part of decl-specifier
int * __declspec(selectany) pi3 = 0;   //ERROR, selectany is not part of a declarator
  • The following code declares an integer thread local variable and initializes it with a value:
  • 译:以下代码声明一个整数线程局部变量,并使用一个值对其进行初始化:
// Example of the __declspec keyword
__declspec( thread ) int tls_i = 1;
原文

docs.microsoft

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值