Elmo HARmonica Network Hardware User Manual


 
HARSFEN0602
y1 = x1; ** Function body
y2 = x2;
if x2 > 0 ** If block
return ** return inside block is not the end of the
function
end ** End of if block
y2 = y1 + y2 ; ** Some executable code
return ** Function end
Before function call, it must be declared. It may be either function prototype or function definition.
For example,
13 function [int y1, int y2] = func
(float x1, int x2) ;
** Function prototype.
function main() ** Function main definition
int a, b; ** Local variable definition
[a,b] = func(2.3, -9.0); ** Function call
return ** Function main end
function [int y1, int y2] = func
(float x1, int x2)
** Function definition
** Function body
return ** Function end
If any function declared without body, its call is illegal.
For example,
14 function [int y1, int y2] = func
(float x1, int x2) ;
** Function prototype.
function main() ** Function main definition
int a, b; ** Local variable definition
[a,b] = func(2.3, -9.0); ** Function call
return ** Function main end
In this example function func has prototype, but has no body, so its call is illegal.
5.6.2 Dummy variables
The input arguments and the output arguments of a function are called dummy variables. A
true variable is substituted for the dummy variable when a function is called.
Example: In the example of the statistic function from the next chapter, variables mean and std are the
dummy variables.
5.6.3 Count of output variables
A function may return multiple values. In some cases, not all the outputs need be computed. A function can
use the nargout keyword –to know how much of its results it actually needs to evaluate.
Number of outputs is the number of items in the left hand side expression during the function call. If its
number exceeds the number of maximal defined output arguments of this function or the maximal
admissible number of output arguments, it’s an error.