HARSFEN0602ElmoHARmonicaSoftwareManual

PRELIMINARYDRAFT

For example,

41

2

function func2 (struct float x1)

This function is named func2, it gets the only input

 

 

argument of float type and doesn’t return any output.

3

[int y1] = func3 (int x1)

This function declaration is illegal, because keyword

 

 

function is absent

4

function y1 = func5

This function prototype is illegal, because type of the

 

 

output variable is absent.

The valid function name observes the same rules as the variable name. It must be distinct from any variable, function or label name.

Definition of dimensions of the output and input arguments at the function declaration is illegal.

For example,

5 function [int x[100]] = func3 () This function declaration is illegal, because dimension of output argument is defined.

Function may have prototype before its declaration. The prototype has the same syntax with function declaration, but it must end with semicolon.

For example,

6

function [float y1] = func4 () ;

This is prototype of function func4 that doesn’t

 

 

has any input argument and returns the only

 

 

output argument

7

function float y1 = func4 ;

It’s the same as the previous example 6.

8

function float = func4 ;

This function prototype is the same as example

 

 

6 and 7. Name of input or output argument of

 

 

the function prototype may be absent, while

 

 

during definition of the function it’s error.

9

function [int, int] = func1 (float, int) ;

This is prototype of the function from the

 

 

example 1. It’s the same as

 

 

function [int y1, int y2] = func1 (float x1, int

 

 

x2) ;

It is allowed to write the prototype of the same function several times (multiple prototype), but all these prototypes must be identical. The names of the input/output arguments in the function prototype may be omitted, or may be different from the name of the corresponding argument names in the function declaration.

For example,

10

function [int y1, int y2] = func

The first expression is the function prototype and

 

(float x1, int x2) ;

the second is the function definition.

 

function [float y1, int y2] = func

It’s not legal, because types of the first output

 

(float x1, int x2)

argument in the prototype and declaration do not

 

 

match.

11

function [int y1, int y2] = func

The first two expressions are the function

 

(float x1, int x2) ;

prototype and the third is the function definition.

 

function [int a, int b] = func (float

It is legal

 

x1, int x2) ;

 

 

function [int y1, int y2] = func

 

 

(float x1, int x2)

 

Body of a function resides below the declaration and must end with the keyword return. If the keyword return is inside some control block within the function body, it is not the end of the function body.

For example,

12 function [int y1, int y2] = func ** Function definition. (float x1, int x2)

Page 43
Image 43
Elmo HARSFEN0602, HARmonica software manual Function is absent