简体   繁体   English

SAL注释,哪一个使用?

[英]SAL annotations, which one to use?

So I have dipped my toes into source code annotations for C++, but discovered there are many ways to Rome, so to speak. 所以我已经将我的脚趾浸入C ++的源代码注释中,但发现罗马有很多方法,可以这么说。

Examples: 例子:

__in

_In_

[Pre(FormatString(Style="printf")] LPCSTR format

Is there one -microsoft-way to do this? 是否有一种 -微软的方式来做到这一点?

Microsoft has introduced a new SAL standard ( SAL 2.0 ) starting with Windows 8 1 . 微软已经推出了新的SAL标准( SAL 2.0 )开始使用Windows 8 1。 SAL 2.0 uses the single underscore style of annotations, such as _In_opt_ among others . SAL 2.0使用单个下划线样式的注释,例如_In_opt_ Thus, for all new code, the best practice would be to follow the SAL 2.0 style, as slides from Microsoft exhibit. 因此,对于所有新代码,最好的做法是遵循SAL 2.0样式,如Microsoft的幻灯片所示

For older code, the general rule of "stay consistent" seems to be the best way to go, but if you feel inclined to update all your annotations, again follow the SAL 2.0 style. 对于旧代码,“保持一致”的一般规则似乎是最好的方法,但如果您想要更新所有注释,请再次遵循SAL 2.0样式。

-- -

1 - SAL 2.0 has actually been around since 2010 (check the date on the linked presentation), but it hasn't been officially supported externally until Windows 8, to the best of my knowledge. 1 - SAL 2.0自2010年以来实际上已经存在(检查链接演示文稿的日期),但据我所知,它在Windows 8之前尚未得到外部官方支持。

可能不是,因为SAL注释是一种元语言,可以帮助静态分析工具在编译时检查错误,我认为它可能是编译器相关的(至少在某种程度上复杂的检查)所以你可能没有 - 所有这些方式,但从一个到另一个的过渡并不太复杂

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

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