C / C ++ function / method decoration

DISCLAIMER: I haven't done C ++ yet ...

Is it customary to decorate C / C ++ function / method declarations today to improve readability?

Uncleaned example:

void some_function(IN int param1, OUT char **param2);

with IN and OUT macros defined with an empty body (i.e. light documentation if you are in this example). Of course, I understand that this is somewhat parallel to the "dock comment block" associated with the method / function.

Could you give some other examples ... if this topic is useful for the community. Please remember that the above example is exactly what it is.

+5
source share
10 answers

I would not appreciate such a decoration.

, ,

void some_function(AClass const &param1, AnotherClass &param2)

int , , AClass AnotherClass . , empy IN OUT .

+17

Windows . . . ,

DWORD
WINAPI
GetModuleFileName(
    __in_opt HMODULE hModule,
    __out_ecount_part(nSize, return + 1) LPTSTR lpFilename,
    __in DWORD nSize
    );

hModule , lpFilename , nSize ( ) +1 , nSize - .

+7

, - . , ; , Doxygen, :

/**
 * @param[in]  param1 ...
 * @param[out] param2 ...
 **/
void some_function(int param1, char **param2);
+5

, . , IN/OUT .

, .

void some_function(/* IN */ int param1, /* OUT */ char **param2);

out, .
pass ref ref ref . , .

void some_function(/* IN */ int const& param1, /* OUT */ char*& param2);
// OK for int const& is kind of silly but other types may be usefull.
+4

++, C- , ++ :

void f( std::string const & ); // input parameter
void f( std::string );         // input parameter again (by value)
void f( std::string& );        // in/out parameter
std::string f();               // output

(doxygen), ( , ...

. . , , . , : shared_ptr < > (, ), auto_ptr < > /unique_ptr < > ( , )...

+2

:

  • ,

, IN OUT, , .

IN, OUT .

+1

, , , "".

Win32 API (C ++) :

WINADVAPI
BOOL
WINAPI
CreateProcessWithLogonW(
    __in        LPCWSTR lpUsername,
    __in_opt    LPCWSTR lpDomain,
    __in        LPCWSTR lpPassword,
    __in        DWORD dwLogonFlags,
    __in_opt    LPCWSTR lpApplicationName,
    __inout_opt LPWSTR lpCommandLine,
    __in        DWORD dwCreationFlags,
    __in_opt    LPVOID lpEnvironment,
    __in_opt    LPCWSTR lpCurrentDirectory,
    __in        LPSTARTUPINFOW lpStartupInfo,
    __out       LPPROCESS_INFORMATION lpProcessInformation
      );

Visual ++ 2005 __$allowed_on_parameter .

+1

, , C, dev:


#define begin {
#define end   }

int main( int argc, char* argv[] )
begin
  ...
end
+1

. , ​​ .

0
source

I saw the use of the i_, o_, io_ prefixes in addition to the information in the parameter types:

void some_function(int i_param1, char** o_param2, int& io_param3);
0
source

All Articles