Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 1.41 KB

c28220.md

File metadata and controls

44 lines (35 loc) · 1.41 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Warning C28220
Warning C28220
12/17/2019
C28220
C28220
64ff46fe-7ce7-491a-b0bb-484500b0267a

Warning C28220

Integer expression expected for annotation 'annotation'

This warning indicates that an integer expression was expected as an annotation parameter, but an incompatible type was used instead. It can be caused by trying to use a SAL annotation macro that doesn't fit the current scenario.

Example

#include <sal.h>

// Oops, the _In_reads_ annotation takes an integer type but is being passed a pointer
void f(_In_reads_(last) const int *buffer, const int *last)
{
  for(; buffer < last; ++buffer)
  {
    //...
  }
}

In this example, the intent of the developer was to indicate that buffer would be read up to the last element. The _In_reads_ annotation doesn't fix the scenario because it's used to indicate a buffer size in number of elements. The correct annotation is _In_reads_to_ptr_, which indicates the end of the buffer with a pointer.

If there was no _to_ptr_ equivalent to the annotation used, then the warning could have been addressed by converting the last pointer into a size value with (buffer - size) in the annotation.

#include <sal.h>

void f(_In_reads_to_ptr_(last) const int *buffer, const int *last)
{
  for(; buffer < last; ++buffer)
  {
    //...
  }
}