Edit

Share via


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)
  {
    //...
  }
}