param [out]和doxygen返回之间的区别? [英] Difference between param[out] and return in doxygen?

查看:164
本文介绍了param [out]和doxygen返回之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

\param [out] 和<在Doxygen中href = http://www.doxygen.nl/manual/commands.html#cmdreturn rel = nofollow noreferrer> \return 吗?它们似乎都记录了函数的输出/返回。是由于 void 函数没有返回值而只有 param [out] 有效而导致的差异吗? ?

What is the difference between \param[out] and \return in Doxygen? They both seem to document the output / return of a function. Is the difference due to void functions which don't have a return value and only param[out] would be valid?

推荐答案

Out参数与返回值不同。以C中的示例为例:

Out parameters are different from return values. Take this example in C:

/**
 * \param[in]  val      Value calculations are based off.
 * \param[out] variable Function output is written to this variable.
 *
 * \return Nothing
 */
void modify_value(int val, int *variable)
{
    val *= 5;
    int working = val % 44;
    *variable = working;
}

该函数不返回任何内容,但返回的值变量点已更改,因此我们将其称为输出参数。它代表函数的输出,因为我们希望函数可以对其进行某种程度的修改。另一方面, val 是一个'input'参数,因为它没有被修改(实际上,从函数调用者的角度来看,不能修改它,因为它是

The function returns nothing, but the value to which variable points is changed, hence we call it an output parameter. It represents an 'output' of the function in that we expect it to be modified somehow by the function. val, on the other hand, is an 'input' parameter because it is not modified (and, indeed, cannot be modified from the perspective of the function's caller, since it is passed as a value).

这是一个更实用和实际的示例:

Here's a slightly more useful and realistic example:

typedef struct data {
    int i;
    int j;
    ...
} data;

/**
 * \param[in]  val Initialising parameter for data.
 * \param[out] dat Data pointer where the new object should be stored.
 *
 * \return True if the object was created, false if not
 *         (i.e., we're out of memory)
 */
bool create_data(int val, data **dat)
{
    data *newdata;
    newdata = (data*)malloc(sizeof(data));
    if(newdata == NULL)
    {
        *dat = NULL;
        return false;
    }
    newdata->i = val;
    *dat = newdata;
    return true;
}

在这种情况下,我们在函数内部构造了一些复杂的对象。我们返回一个简单的状态标志,使用户知道对象创建成功。但是我们使用out参数来传递新创建的对象。

In this case, we construct some complex object inside the function. We return a simple status flag that lets the user know the object creation was successful. But we pass out the newly-created object using an out parameter.

(尽管,当然,该函数可以很容易地返回一个指针。某些函数更复杂! )

(Although, of course, this function could easily just return a pointer. Some functions are more complex!)

这篇关于param [out]和doxygen返回之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆