Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Examples:

__in

_In_

[Pre(FormatString(Style="printf")] LPCSTR format
  • VS2005 SAL Annotations
  • VS2010 Using Annotations to Reduce C/C++ Code Defects
  • VS2012 Using SAL Annotations to Reduce C/C++ Code Defects

Is there one-microsoft-way to do this?

like image 792
CS. Avatar asked Aug 22 '12 04:08

CS.


2 Answers

Microsoft has introduced a new SAL standard (SAL 2.0) starting with Windows 81. SAL 2.0 uses the single underscore style of annotations, such as _In_opt_ among others. Thus, for all new code, the best practice would be to follow the SAL 2.0 style, as slides from Microsoft exhibit.

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.

--

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.

like image 106
brc Avatar answered Nov 19 '22 16:11

brc


Probably not, since SAL annotations is a meta-language that can help static analysis tools to check the for bug at compile time, I think it might be compiler dependent ( for complex checks at least to some extent ) So you might not have one-way for all of them, but the transition from one to the other is not too complicated

like image 1
MimiEAM Avatar answered Nov 19 '22 14:11

MimiEAM