From SoftMC-Wiki
Jump to: navigation, search

Imports a user C function into a task. In order for the Translator to match function parameters the user has to provide C-function prototype.

Important to note that matching between provided softMC prototype and actual C implementation cannot be tested by Translator, thus it is the user’s (programmer) responsibility to keep consistency between function prototype and C implementation.

The MC-Basic Translator needs a function prototype in order to translate a user program. All the function prototypes will be concentrated in the single predefined file - Since all the C-functions are global it is enough to have only one prototypes file. The Translator will use this file during translation of user programs and for command line.  It will include a list of C-function prototypes. The Translator is optimized to re-translate this file only if needed.Prototypes do not include parameters’ names. A prototype of a C-function with no parameters is written with empty parenthesis:

IMPORT_C<Function_Name> ( ) {AS <return_value_type>}

A C-function will accept any combination of double-, long- and string-type parameters. The parameters may be passed “by value”(with the BYVAL prefix) or “by reference”(without any prefix). Arrays cannot be passed as parameters.

The returned value may be either long, double, string, ornone (for C functions with void returned value).


Translator is case-insensitive, while object module loader is case-sensitive, so the name of a C function should be written in capital letters within the C code.

On the other hand, MC-Basic prototypes of C functions, as well as C function calls through MC-Basic, are not case sensitive.

Object files , including user C functions , must be loaded (using oload command) prior to using the C-functions that it contains. This means that a single MC-Basic application program cannot use load an object file and use it’s functions – if an application task wishes to use C-functions, the object file must be loaded before loading the task.


IMPORT_C <Function_name>({ {ByVal} as parameter_type>}, { {ByVal} AS <parameter_type>}) {AS <return_value_type>}


Since Version 3.6.20
Scope was expanded to libraries since version 4.9.12


Task, Library, PROTO.PRO


Library must be loaded into memory (using load command).


Import_C Cfunc1 (As Long, ByVal As Double, As String) As Long

Import_C Cfunc2 (As Double, ByVal As Long, ByVal As String)

Import_C Cfunc3 ( ) As String

Where C-implementation of CFUNC1 will be as follows:

int CFUNC1 (int * par1, double par2, char ** par3)



Whereas the C-implementation of CFUNC2 and CFUNC3 will be, respectively:

void CFUNC2 (double * par1, int par2, char * par3)



char* CFUNC3 (void)



User C Functions calling from MC-Basic :

LongVar = cfunc1 (LongVar, 3.3, StringVar)

Print CFUNC3 ()

CFunc2 (DoubleVar, 2, “OK”)

Sending handle of motion element is done with elementID (integer) property.

Sending group location is done with generic location:

int example(int axisHandle, SYS_POINT * point) { }

IMPORT_C example(byval as long, as generic location) as long

See Also