Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
 How to: Specify Additional Code Inf...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual Studio Team System
How to: Specify Additional Code Information

You can provide hints to the code analysis tool that will help the analysis process and reduce warnings. To provide additional information, use the following function:

__analysis_assume( expr )

expr - any expression that is assumed to evaluate to true.

The code analysis tool assumes that the condition represented by the expression is true at the point where the function appears and remains true until expression is altered, for example, by assignment to a variable.

NoteNote

__analysis_assume does not impact code optimization. Outside the code analysis tool, __analysis_assume is defined as a no-op.

Example

The following code uses __analysis_assume to correct warning C6388:

#include<windows.h>
#include<codeanalysis\sourceannotations.h>

using namespace vc_attributes;

// calls free and sets ch to null
void FreeAndNull(char* ch);

//requires pc to be null
void f([Pre(Null=Yes)] char* pc);

void test( )
{
  char *pc = (char*)malloc(5);
  FreeAndNull(pc);
  __analysis_assume(pc == NULL); 
  f(pc);
}

See Also

Reference

__assume

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker