beautypg.com

Simpliq – ElmoMC SimplIQ Software Manual User Manual

Page 52

background image

SimplIQ

Software Manual

4BThe

SimplIQ

User Programming Language

MAN-SIMSW (Ver. 1.4)

5-23

Example 6:
function [float y1] = func4 () ;
A prototype of function func4 that has no input argument and returns only the output
argument.

Example 7:
function float y1 = func4 ;
Same as example 6.

Example 8:
function float = func4 ;
Same as examples 6 and 7. The name of input or output argument of the function prototype
may be omitted, but during function definition, it will be an error.

Example 9:
function [int, int] = func1 (float, int);
Prototype of function from example 1. Same as function [int y1, int y2] = func1
(float x1, int x2) ;

The prototype of the same function can be written several times (multiple prototype), but all
prototypes must be identical. The names of the input/output arguments in the function
prototype may be omitted, or may be different from the names of the corresponding
argument names in the function declaration.

Example 10:
function [int y1, int y2] = func (float x1, int x2) ;

function [float y1, int y2] = func (float x1, int x2)
The first expression is the function prototype and the second is the function definition. This
is illegal because the type of first output argument in the prototype does not match that of
the declaration.

Example 11:
function [int y1, int y2] = func (float x1, int x2) ;

function [int a, int b] = func (float x1, int x2) ;

function [int y1, int y2 ] = func (float x1, int x2)
The first two expressions are the function prototype and the third is the function definition,
which is legal.

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

Example 12:
function [int y1, int y2] = func (float x1, int x2)

Function

definition.

y1 = x1;

Function body

y2 = x2;

if x2 > 0

If block

Return

return inside block is not
end of the function

end

End of if block