在阅读jQuery文档时,原本不注意的两个英文单词paramter 和argument引起了我的注意,为什么特定的语义环境下用特定的单词?至少他们两个之间应该有区别,但究竟区别何在呢?我做了一番搜索,经过对比总结,发现一篇中的内容比较有道理,居然是英文的。虽然也找到了一些中文关于两个词的比较,但感觉没有这个全面,而且一下就得到的结论总觉得靠不足。现在把原文贴出来,留作备忘。
The words argument and parameter are often used interchangeably in the literature, although the C++ Standard makes a clear distinction between the two. An argument is one of the following: an expression in the comma-separated list in a function call; a sequence of one or more preprocessor tokens in the comma-separated list in a macro call; the operand of a throw-statement or an expression, type, or template-name in the comma-separated list in the angle brackets of a template instantiation. A parameter is one of the following: an object or reference that is declared in a function declaration or definition (or in the catch clause of an exception handler); an identifier between the parentheses immediately following the macro name in a macro definition; or a template-parameter. This example demonstrates the difference between a parameter and an argument:
void func(int n, char * pc); //n and pc are parameters
template <class T> class A {}; //T is a a parameter
int main()
{
char c;
char *p = &c;
func(5, p); //5 and p are arguments
A<long> a; //'long' is an argument
A<char> another_a; //'char' is an argument
return 0;
}
虽然文章是以c++语言做的解释,但从另外一个角度佐证了parameter是形参而argument是实参。
原文出处:Understanding the Difference Between an Argument and a Parameter