C6388

更新:2007 年 11 月

警告 C6388:<argument> 不能是 <value>: 这不符合函数 <function name> 的规范: 行: x, y

此警告意味着在指定的上下文中使用了意外的值。通常,如果将值作为参数传递到不接受它的函数,则会报告此警告。

示例

在下面的 C++ 代码中,因为 DoSomething 接受 null 值,但是传递的可能是非 null 值,所以会生成此警告:

#include <string.h>
#include <malloc.h>
#include <codeanalysis\sourceannotations.h>
using namespace vc_attributes;

void DoSomething( [Pre( Null=Yes )] void* pReserved );
 
void f()
{
    void* p = malloc( 10 );
    DoSomething( p );  // C6388
    // code...
    free(p);
}

若要更正此警告,请使用下面的代码示例:

#include <string.h>
#include <malloc.h>
#include <codeanalysis\sourceannotations.h>
using namespace vc_attributes;

void DoSomething( [Pre( Null=Yes )] void* pReserved );

void f()
{
  void* p = malloc( 10 );
  if (!p)
  {
    DoSomething( p );  
  }
  else
  {
    // code...
    free(p);
  }
} 

请参见

概念

批注概述