什么是一个正式的参数? [英] What is a formal parameter?

查看:190
本文介绍了什么是一个正式的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用C ++编译我经常结束了对付形式参数,如

When compiling in C++ I often end up with error messages dealing with "formal parameters", such as

error C2719: 'b': formal parameter with __declspec(align('16')) won't be aligned

我不理解错误,而事实上, B 是我定义一个函数的参数。

I do understand the error, and the fact that b is a parameter of a function I am defining.

不过,这是什么意思,一个参数的正式的?哪有的非正式的参数呢?

However, what does it mean that a parameter is formal? Can there be informal parameters as well?

我也注意到,所谓形参出现在其他语言一样,所以我presume它是一个更通用的术语不一定特定于语言C家族?是非正式的参数通过语言某个子集的支持?

I do notice that the term "formal parameter" appears in other languages as well, so I presume it is a more generic term not necessarily specific to C-family of languages? Are informal parameters supported by some subset of languages?

见状答案,最后一个问题:当这些名字的形式参数的和的实际参数的从起点?它是否起源与C标准,或者是调用它这样一些抽象的语言演算的效果?

Upon seeing the answers, one final question: Where those names formal parameter and actual parameter origin from? Does it origin from the C standard, or is it an effect of calling it as such in some abstract language calculus?

推荐答案

正式的和的实际的参数:

void foo(int arg); //arg is a formal parameter

int main()
{
    int val = 1;
    foo(val);  //val is an actual parameter
}

C ++标准:

1.3.1形式参数(参数)

一个对象或引用声明为函数声明的一部分或
  定义或异常处理程序的catch子句中,这
  收购在进入函数或处理的值;一个标识符
  从马上括号包围的逗号分隔的列表
  下面的函数宏定义宏的名称;或
  模板参数。参数也被称为正式的参数或
  形式参数。

an object or reference declared as part of a function declaration or definition, or in the catch clause of an exception handler, that acquires a value on entry to the function or handler; an identifier from the comma-separated list bounded by the parentheses immediately following the macro name in a function-like macro definition; or a template-parameter. Parameters are also known as formal arguments or formal parameters.

1.3.10实际参数(参数)

由括号包围的逗号分隔列表中的前pression
  在函数调用前pression,preprocessing令牌的序列
  在括号中的函数一样围成的逗号分隔的列表
  宏调用,抛的操作数,或前pression,类型ID或
  模板的名称由角度界定的逗号分隔的列表
  括号模板实例。也被称为实际参数
  或实际参数。

an expression in the comma-separated list bounded by the parentheses in a function call expression, a sequence of preprocessing tokens in the comma-separated list bounded by the parentheses in a function-like macro invocation, the operand of throw, or an expression, type-id or template-name in the comma-separated list bounded by the angle brackets in a template instantiation. Also known as an actual argument or actual parameter.

这篇关于什么是一个正式的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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