Page 5 - Demo
P. 5
Interface to C/C++%uf09f %uf09f RCP Consult 2023-2025 Page 54. Interaction between STRUREL and C/C++A major part of communication with the C/C++ Interface is usage of source files with extension %u2019.c%u2019 for a C language or with extension %u2019.cpp%u2019. for a C++ language. With the classic computer language such as C/C++ the creation of Add-on is more complex as compared to usage of external engines like PYTHON or others. You need source file compiler, librarian, resource file compiler and linker to create a customized Windows DLL. Using special rules for creation of resource file such a C/C++ based DLL can be built directly. Then, it will be accepted as so called Buildout Add-on and connected with STRUREL. The integration of Buildout Add-on in STRUREL is provided by using the DEFFUNC keyword in Symboliclanguage.The syntax of DEFFUNC for interaction with such a C/C++ based Add-on is:DEFFUNC(i, k | l, SAONAME)(PARAMETERLIST){COMMENT}=FUNNAME%uf046 i: ID of the user defined function in Symbolic Interpreter%uf046 k: kind of Add-on as number: 2 %u2013 C/C++or%uf046 l: language as text: C, CPP%uf046 SAONAME: name of the Add-on (without extension .sao)%uf046 PARAMETERLIST: lists the parameters the function expects. The names given are arbitrary. The parameter list can be empty or have maximal 16 members.%uf046 COMMENT: some comment (may be omitted)%uf046 FUNNAME: the name of the export function to callThe user defined function with arguments can be expressed in the Symbolic language of STRUREL as shown below. DEFFUNC(1,2,CppSAO,\ {Uses function arguments}=CppFunctionorDEFFUNC(1,CPP,CppSAO,\ {Uses function arguments}=CppFunctionIf you wish to create an Add-on using g++, c++ or cl you may prepare a C++ source file%u2018CppSource.cpp%u2019 with definition of an export function like //* Include file with internal STRUREL definitions#include \extern \{//* Export function definition for usage in STRUREL DllExport double CppFunction(double, double, double, double, long *);}double CppFunction(double a, double b, double c, double d, long *ier){/*Uses function argument values as defined in Symbolic Expressions.The sequence is predefined by definition of parameters of DEFFUNC.*/ *ier=0; return a*b/4*c-d;}