奇怪的 SAL 注释警告 [英] Strange SAL annotation warning
问题描述
我正在尝试为我的项目使用 Micosoft 的 SAL 注释,但是我收到以下警告,我不知道为什么.
I'm trying to use Micosoft's SAL annotation for my project, however I get the following warning, and I don't know why.
例如,我创建了一个新的 C++ 控制台应用程序,并有以下代码:
As an example, I created a new C++ console application, and have this code:
#include <sal.h>
class Whatever
{
public:
_Check_return_ int Method(__in int number) ;
};
int main()
{
return 0;
}
当我使用 Visual Studio 2008 进行编译时,我收到以下警告:
When I compile using Visual Studio 2008, I get the following warning:
警告 C6540:在此函数上使用属性注释将使其所有现有的 __declspec 注释无效
warning C6540: The use of attribute annotations on this function will invalidate all of its existing __declspec annotations
在文件c1xxast"中
In the file "c1xxast"
我做错了什么?如果我删除 _Check_return_
或 __in
,警告就会消失.
What am I doing wrong? If I remove either the _Check_return_
or the __in
, the warning goes away.
我找不到对警告 C6550 的任何参考.但是,可以在此处找到相同的文本:http://msdn.microsoft.com/en-us/library/dd445322.aspx,但不是很有帮助.
I cannot find any reference to the warning C6550. However the same text can be found here: http://msdn.microsoft.com/en-us/library/dd445322.aspx, but it's not very helpful.
推荐答案
问题可能是因为您混合了 SAL 注释类型.虽然在 MSDN 上说得很清楚,但是 SAL 注释有两种类型:attribute 和 ... er ... not.
The problem may be because you are mixing SAL annotation types. Although made very clear on MSDN, there are two types of SAL annotation: attribute and ... er ... not.
VC2005 中的#define
s 使用非属性版本并以下划线开头,后跟小写 信.较新的 VC2008 版本扩展到编译器属性,并以下划线开头(和结尾),后跟大写字母.
The #define
s in <sal.h>
VC2005 use the non-attribute versions and start with an underscore followed by a lowercase letter. The newer VC2008 versions expand to compiler attributes and start (and end) with an underscore followed by a capital letter.
您混合了两种类型:
属性:
- _In_
- _Check_return_
非属性:
- __in
- __checkReturn
尝试更改注释以一致地使用单一类型.
Try changing your annotations to use a single type consistently.
这篇博文对此进行了更多解释.
这篇关于奇怪的 SAL 注释警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!