7

What is the difference between the following SAL annotations?

void foo(__deref_out_opt PSTR* bar);

void foo(__deref_opt_out PSTR* bar);
John
  • 5,561
  • 1
  • 23
  • 39

1 Answers1

6

A PSTR* out parameter means the caller passes in a buffer which receives a pointer to a string.

In __deref_out_opt, the string is optional (the function puts NULL in the caller-provided buffer).

In __deref_opt_out, the buffer is optional (the caller passes NULL to indicate disinterest in the output value).

Presumably, it's possible to combine these concepts, there should be a __deref_opt_out_opt modifier for that.

yzxben
  • 862
  • 6
  • 11
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Where do I put the _opt for the "other case" where the function may set the output parameter to NULL? – John Jan 24 '11 at 16:28
  • After `out`, as in `__deref_out_opt`. The SAL documentation describes the case of `__deref_opt` specially, and in that case the buffer may not exist. You want the buffer to exist, hence plain `__deref`, but the pointer stored in it can be NULL, hence `_out_opt`. – Ben Voigt Jan 24 '11 at 17:00