C++ source_annotation_attribute
C++ source_annotation_attribute
在浏览开源.NET Framework 4.7的源代码时,我偶然发现了C++标头sal.h
,并发现了一行代码,上面写着[source_annotation_attribute( SA( Method ) )]
,这似乎类似于C#中的属性和AttributesUsage
类。
现在我知道,一般来说,C++中没有像 C# 那样的用户定义属性,我的第一个猜测是[source_annotation_attribute( SA( Method ) )]
只是一个宏,但它既没有在sal.h
中定义,也没有在任何其他标头中定义,因为sal.h
没有#include
任何。
我的下一个猜测是[source_annotation_attribute]
实际上是在 MSVC 中构建的,就像例如[[noreturn]]
属性。
如果有人能阐明它实际上是什么,并且如果我可以声明我自己的类似属性,如果它没有内置到编译器中,我会很高兴。 如果您想自己查看,则Sourceexternalapislegacyvctoolsvc12incvcsal.h
特定文件,并且该属性(除其他外(出现在第1934
行中。
以下是sal.h
中的用法示例:
[source_annotation_attribute( SA( Method ) )]
struct __M_
{
#ifdef __cplusplus // [
__M_();
#endif // ]
int __d_;
};
typedef struct __M_ __M_;
提前非常感谢。
总结@VTT已经说过的内容,看起来source_annotation_attribute
是一个编译器内置结构,它是作为Microsoft扩展的一部分提供的C++ (即使那里没有提到它,因为它是一个实现细节,仅供内部使用(仅在使用编译器开关/Ze
编译时才有效
除此之外,微软的SAL是在Visual Studio中深深内置的。 即
生成 -> 对解决方案运行代码分析 由于Visual Studio(显然(使用他们的MSVC编译器,因此Microsoft不会在编译器中构建任何这样的内部结构并不是太不可信。
- C++ variable_name.attribute = x
- 需要帮助调试"attribute parser"!C++ 来自黑客排名的问题
- C++生成器 10.2 基于函数的优化状态"unknown attribute 'optimize' ignored"
- 禁止显示"use of the 'X' attribute is a C++17 extension"警告
- C++14 类函数错误:"Object has no attribute 'value'"
- "Attribute is protected within this context"继承和 .h 和.cpp文件
- 使用 Python.h 时"AttributeError: 'module' object has no attribute 'argv'"
- 术语"attribute"在解析器的上下文中是什么意思?
- 如何阅读C++中的NetCDF "global attribute"
- 为什么在这种情况下是this->属性而不是this.attribute(C++OOP)?
- 如何使用"PASCAL Annotation"文件通过C++训练 SVM
- java annotation vs c++ pragma
- 为什么不允许"empty attribute block"?
- C++, Qt :释放在构造函数中创建的"non attribute"对象