4

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

  • 1
    First of all, the leading underscore followed by a capital letter in `_Return_type_success_` means that this is a reserved name, and you shouldn't use it in your own code. This might not be portable or standards-compliant is not something that you're meant to understand. If you want to learn C++, you should read [documentation](https://en.cppreference.com/w/) and get [a good C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). Do not learn from trying to read your compiler's internals. – alter_igel May 04 '19 at 18:09
  • This code does not compile ([live example here](http://coliru.stacked-crooked.com/a/0d1dafc21b83b7e8)). Could you provide more context about where you found it? It probably relies on a specific compiler's quirks. – alter_igel May 04 '19 at 18:12
  • found a copy of this code here might offer a bit more context http://89.75.105.17/git/Repository/Blob/06f3f29b-97ba-4f57-bb14-3c3d0fc46b4a?encodedName=master&encodedPath=CommonTypes.h, looks like visual studio internals, definitely not standard c++ – Alan Birtles May 04 '19 at 18:16

1 Answers1

6

_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.

t.niese
  • 39,256
  • 9
  • 74
  • 101