Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return argument in function parameter of C++

Tags:

c++

I am trying to understand a typedef but I am stuck with this Code:

   typedef _Return_type_success_(return == DUPL_RETURN_SUCCESS) enum
   {
    DUPL_RETURN_SUCCESS             = 0,
    DUPL_RETURN_ERROR_EXPECTED      = 1,
    DUPL_RETURN_ERROR_UNEXPECTED    = 2
   }DUPL_RETURN;

My question is:

1) What is the Return argument doing in parameter of a function

2) we usually define typedef like this

 typedef int foo;

I am unable to understand this above format.

I am a noobee to serious c++ programming, Thankyou for your time.

EDIT: I am trying to build this streaming app, so I need to retrieve frames as fast as possible, I came across a few articles that recommended DXGI way which is a fast solution. I am trying to understand how to use the windows desktop Duplication API. I found this code on official msdn website : here

like image 494
Kislay Kunal Avatar asked Sep 15 '25 05:09

Kislay Kunal


1 Answers

_Return_type_success_ it is not part of the official c++ standard, but part of the Microsoft source code annotation language (which is proprietary addition to the c++ syntax):

Using SAL Annotations to Reduce C/C++ Code Defects
SAL is the Microsoft source code annotation language. By using source code annotations, you can make the intent behind your code explicit. These annotations also enable automated static analysis tools to analyze your code more accurately, with significantly fewer false positives and false negatives.

And _Return_type_success_ itself is described in Success/Failure Annotations

_Return_type_success_(expr): May be applied to a typedef. Indicates that all functions that return that type and do not explicitly have _Success_ are annotated as if they had _Success_(expr). _Return_type_success_ cannot be used on a function or a function pointer typedef.

_Return_type_success_ is most certainly just a macro defined as #define _Return_type_success_(arg) so that it is completely removed while compiling. This is at least the case for the sal.h (no_sal2.h ) header used in some azure code.

like image 56
t.niese Avatar answered Sep 17 '25 18:09

t.niese