|
If a name that has not been described before appears in an expression and
is followed by the left parenthesis, it will be contextually considered
as the name of a function.
もし、事前に記載されていない名前で式が現れ、その後に丸括弧が続いていれは、その文脈は関数の名前として見なされます。
function_name (x1, x2,..., xn)
Arguments ( formal parameters) are passed by value, i.e., each expression xl, . . . , xn is calculated,
and the value is passed to the function. The order of expressions calculation
and that of values loading are guaranteed. During the execution, the system
checks the number and type of arguments given to the function. Such way
of addressing to the function is called a value call. Function call is
an expression thy value of which is the value returned by the function.
The function type described above must correspond with the type of the
returned value. The function can be declared or described in any part of
the program on the global scope, i.e., outside other functions. The function
cannot be declared or described inside of another function.
引数(仮引数)は渡される値です。すなわち、xl , . . . , xn はそれぞれの式が計算され、その値が関数に渡されます。式の計算の順序と値の読み込みは保証されています。実行中に、システムは関数に指定された引数の型と数をチェックします。このようなアドレス指定の方法は、関数の値の呼び出しと呼ばれます。関数の呼び出しは、その関数の戻り値の式の値です。上記は、関数の型と戻り値の型が一致している必要があります。関数は、グローバルスコープ、いわゆる外部のほかの関数の上で、プログラムのどんな部分にでも宣言するか、記載することができます。関数は別の関数の内部では宣言したり、記載することはできません。
Examples:
例:
int start()
{
double some_array[4]={0.3, 1.4, 2.5, 3.6};
double a=linfunc(some_array, 10.5, 8);
//...
}
double linfunc(double x[], double a, double b)
{
return (a*x[0] + b);
}
At calling of a function with default parameters, the list of parameters
to be passed can be limited, but not before the first default parameter.
規定のパラメータを持つ関数を呼び出すことにおいて、渡されるパラメータの一覧を限定することができます。しかし、最初の規定パラメータの前ではできません。
Examples:
例:
| void somefunc(double init,double sec=0.0001,int level=10); |
// |
function prototype 関数原型 |
| somefunc(); |
// |
wrong call, the first required parameter must be presented. 間違った呼び出し、最初の必須パラメータを提示しなければなりません。 |
| somefunc(3.14); |
// |
proper call 適切な呼び出し |
| somefunc(3.14, 0.0002); |
// |
proper call 適切な呼び出し |
| somefunc(3.14, 0.0002, 10); |
// |
proper call 適切な呼び出し |
|
When calling a function, one may not skip parameters, even those having default values:
関数を呼び出すとき、規定値を持っていたしても、1つのパラメータも省略してはいけません。
| somefunc(3.14, , 10); |
// |
wrong call. the second parameter was skipped. 間違った呼び出し。2番目のパラメータはスキップされました。 |
|
|