2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2009 - DIGITEO - Allan CORNET
5 // This file is distributed under the same license as the Scilab package.
8 // CALLING EXTERNAL C FUNCTION
10 if haveacompiler() then
13 // we use TMPDIR for compilation
15 foo=['void foo(double *a,double *b,double *c)';
16 '{ *c = *a + *b; }' ];
19 mprintf(gettext('C Function to call in scilab.\n'));
23 if ~c_link('foo') then
24 cur_ilib_verbose = ilib_verbose();
31 mprintf(gettext('Call ilib_for_link to build C function.\n'));
32 ilib_for_link(['foo'],'foo.c',[],"c");
35 ilib_verbose(cur_ilib_verbose);
38 //Z = X+Y by C function
42 mprintf(gettext('Call C function. Z = X+Y'));
44 mprintf(gettext('with X = %d'), X);
46 mprintf(gettext('with Y = %d'), Y);
48 mprintf("Z = call(''foo'', X, 1, ''d'', Y, 2, ''d'', ''out'', [1,1], 3, ''d'');");
50 Z = call('foo', X, 1, 'd', Y, 2, 'd', 'out', [1,1], 3, 'd');
51 mprintf(gettext('result Z = %d'), Z);