Use the DEFFUN statement to declare an external jBASE BASIC function to the jBASE BASIC compiler and optionally define its arguments. Use DEFFUN in the program that calls the function.
Argument specifies a value passed to the function by the calling program. To pass an array, the keyword you must use the MAT before the argument name. These parameters are 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.
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 passed to the function by the calling program. To pass an array, the keyword you must use the MAT before the argument name. These parameters are 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 jBASE BASIC compiler, which 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 the function returns an empty string.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)Call standard UNIX functions directly by declaring them with the DEFC statement according to their parameter requirements. However, they may only be called directly providing they return one of the type int or float/double or that the return type may be ignored.
Example 2
DEFC INT getpid() CRT "Process id =":getpid()
0 comments:
Post a Comment