[Ecls-list] How to define c function for lisp with X arguments?

Juan Jose Garcia-Ripoll juanjose.garciaripoll at gmail.com
Fri Nov 9 20:59:52 UTC 2012


On Tue, Nov 6, 2012 at 12:31 AM, Peter Enerccio <enerccio at gmail.com> wrote:

> I am using this kind of macro:
>

> #define DEFUN( name, argcount, fpointer) do { \
>     cl_def_c_function(c_string_to_object(name), \
>             (cl_objectfn_fixed)fpointer, \
>             argcount); \
>     } while (0)
>
>
This code is wrong. If you want to create a function with a variable number
of arguments, the function F should have signature

cl_object F(cl_narg narg, ...)

and be defined with

ecl_def_c_function_va(symbol, F)

If you instead want to use a function with a fixed number of arguments (say
2), then the signature should be

cl_object F(cl_object arg1, cl_object arg2)

and be defined with

ecl_def_c_function(symbol, F, 2)

But this is strongly discouraged and not future proof: write the code in
lisp and let ECL compile it.

Juanjo

-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20121109/c412a95f/attachment.html>


More information about the ecl-devel mailing list