The following pairs of function signatures compare SAL annotated functions versus plain C++ functions. The meaning of the SAL macros can be found here. We can assume that SAL functions use the return value to indicate errors whereas the plain C++ functions throw exceptions instead.
HRESULT foo( _In_ obj * pData );
void foo( const obj & data );
HRESULT foo( _Inout_ obj * pData );
void foo( obj & data );
HRESULT foo( _Out_ obj * ppData );
obj foo();
HRESULT foo( _Outptr_ obj * * ppData );
obj & foo();
HRESULT foo( _In_opt_ obj * pData );
void foo( const obj * data );
HRESULT foo( _Inout_opt_ obj * pData );
void foo( obj * data );
HRESULT foo( _Out_opt_ obj * pData );
???
HRESULT foo( _Outptr_opt_ obj * * ppData );
obj * foo();
-
What would be the function signature corresponding to an _Out_opt_ parameter?
-
Would a smart compiler be able to do the same checks using the C++ signatures as the Visual Studio Code Analysis Tool does using SAL?
-
Are there other advantages? For example,
void foo( const obj & data );prolongs the lifetime of temporary objects so that the destructor is guaranteed to be called (sometime) afterfooreturns.
Aucun commentaire:
Enregistrer un commentaire