c++visual-studio-2010visual-studiovisual-c++annotations

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

Is there one-microsoft-way to do this?


Solution

  • 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.