Link Scilab/C : Problem passing char* to a C function from Scilab
Charles G.
cgerardi at edu.univ-fcomte.fr
Wed May 5 15:23:17 CEST 2010
Hello,
I'm currently working on Scilab functions and I need to call a C++ function.
To do so, I need to go through a C function which does the link between
C++ and Scilab.
I succeeded in calling dynamically the C function from Scilab, but I still
have an issue passing matrix of char* as an "in" argument.
With the following function :
void callQuantitative(char* model, int* lengthModel, int* nbL, int* nbC){
printf("%s\n",model);
}
I tried the following example :
/* These 3 first lines are to load dynamically the C function */
exec('callQuantitative.sce');
exec('functionLoader.sce');
loadFunction('callQuantitative','libcallQuantitative');
/* Then we initialize the arguments we are going to give to the C function */
model = ["Test"];
lengthModel = length(model);
[nbL,nbC] = size(model);
/* Finally we call the function */
call('callQuantitative',model,1,'c',lengthModel,2,'i',nbL,3,'i',nbC,4,'i');
As a result, I get the following error message :
call('callQuantitative',model,1,'c',lengthModel,2,'i',nbL,3,'i',nbC,4,'i')
ans =
i
Attention: problème avec la pile ... nettoyé.
The error message is : "Warning: Problem with the stack ... cleaned)."
Note that the printf in the C function is done but weirdly in writes
the name of the C function (ie. "callQuantitative").
Also another issue I encountered concerns 2D float or integer matrix.
It seems that if we give a 2D matrix to a C function, it is actually
given as a single dimension matrix.
So I would like to know if it's a normal behavior or if it's possible to
actually give the 2D matrix as to be used as a real 2D matrix in the
C function.
Thank you.
Charles G.
More information about the users
mailing list