DEFFUN


The DEFFUN statement is used to declare an external jBC function to the jBC compiler and optionally define its arguments. DEFFUN is used in the program that calls the function.

 

COMMAND SYNTAX

DEFFUN FuncName  ({ {MAT} Argument1, {MAT} Argument2...})

 

SYNTAX ELEMENTS

FuncName is the name used to define the function. It must be the same as the source file name.

Argument specifies a value that is passed to the function by the calling program. To pass an array, the keyword MAT must be used before the argument name. These parameters are entirely optional (as indicated in the Command Syntax) but can be specified for clarity. Note that if the arguments are not initialized somewhere in the program you will receive a compiler warning.

 

NOTES

The DEFFUN statement identifies a user-written function to the jBC compiler. It must be present in each program that calls the function, before the function is called. A hidden argument is passed to the function so that a value can be returned to the calling program. The return value is set in the function using the RETURN (value) statement. If the RETURN statement specifies no value then an empty string is returned by the function.

 

EXAMPLE 1

DEFFUN Add()
A = 10
B = 20
sum = Add(A, B)
PRINT sum
X = RND(42)
Y = RND(24)
PRINT Add(X, Y)

FUNCTION Add(operand1, operand2)
result = operand1 + operand2
RETURN(result)

Standard UNIX functions may be called directly be declaring them with the DEFC statement according to their parameter requirements. However, they may only be called directly providing they return one of the types int or float/double or that the return type may be ignored.

EXAMPLE 2

DEFCE INT getpid()
CRT "Process id =":getpid()


jBC