若要在 C 中為程式碼加註,必須包含 SourceAnnotations.h 檔,然後使用屬性 (Attribute) 加註函數參數或傳回值。
若要在 C 中為程式碼加註
將 #include <CodeAnalysis/SourceAnnotations.h> 檔加入至專案標頭檔中。
接著,使用屬性 (Attribute) 加註程式碼。
範例
下列程式碼會顯示如何為 C 程式碼加註:
// MyCode.h
#include <CodeAnalysis/SourceAnnotations.h>
// MyCode.c
#include "MyCode.h"
void f ( [SA_Pre (Valid = SA_Yes)] int pWidth )
{
// code...
}
C++ 中的 SA_ 前置詞是選擇項。