[plt-scheme] FFI, argc and argv

From: Jon Rafkind (workmin at ccs.neu.edu)
Date: Sun May 6 10:13:48 EDT 2007

Paulo J. Matos wrote:
> Hello all,
>
> If I have a function in C that receives int argc, and char **argv,
> what's the best way to warp it up?
>
> Two issues come to my mind:
> - command-line-arguments do not provide, afaik, argv[0].
> - I would have to convert the vector (command-line-arguments) to a
> cvector and pass it up to the function. Something like (list->cvector
> (vector->list (command-line-arguments)) _string) however I'm not sure
> if this is the best way to handle things.
FWIW thats how I would do it. If you want argv[0], which I doubt the C 
function really needs, you could just attach a bogus value of "mzscheme" 
or something to it.

(let ((num-args (add1 (length (command-line-arguments))))
        (args (list->cvector (vector->list (cons "mzscheme" 
(command-line-arguments))))))
  (c-func num args))


Posted on the users mailing list.