Sunday, April 17, 2011

jBase Infobasic Function DEFC

Use the DEFC statement to declare an external C function to the jBASE BASIC compiler, define its arguments, and return types.

Command Syntax

DEFC {FuncType} FuncName ({ArgType {, ArgType ...}})

Syntax Elements

FuncType and ArgType are selected from one of INT, FLOAT or VAR. FuncType specifies the type of result that the function will return. Assumes INT if FuncType is omitted. The optional list of ArgTypes specifies the argument types that the C function will expect. The compiler must know this in advance, as it will automatically perform type conversions on these arguments.

Notes

Compile a DEFC for each C function before making any reference to it else the compiler will not recognize the function name.
The function is called in the same manner, as it would be in a C program, which means it can be used as if it was an intrinsic function of the jBASE BASIC language and therefore returns a value. However,specifying it as a standalone function call causes the compiler to generate code that ignores any returned values.
When passing jBASE BASIC variables to a C function, you must utilize the predefined macros to access the various data types it contains. C functions are particularly useful for increasing the performance of tight loops that perform specific functions. The jBASE BASIC compiler must cater for any eventuality within a loop (such as the controlling variable changing from integer to floating point). A dedicated C function can ignore such events, if they are guaranteed not to happen.
The jBASE BASIC programmer may freely ignore the type of argument used when invoking the C function, as the jBASE BASIC compiler will automatically perform type conversion.

Example 1

DEFC INT cfunc( INT, FLOAT, VAR)

Var1 = cfunc( A, 45, B)

cfunc( 34, C, J)

You can call standard UNIX functions directly by declaring them with the DEFC statement according to their parameter requirements. You can only call them 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

 

Blog Info

A Pakistani Website by Originative Systems

Total Pageviews

Tutorial Jinni Copyright © 2015 WoodMag is Modified by Originative Systems