Re: Mathlink: How do I pass arbitrary data from Mathematica to C?
- To: mathgroup at smc.vnet.net
 - Subject: [mg86919] Re: Mathlink: How do I pass arbitrary data from Mathematica to C?
 - From: Karen Bindash <KarenBindash at googlemail.com>
 - Date: Wed, 26 Mar 2008 04:53:29 -0500 (EST)
 - References: <fs4rmb$p3s$1@smc.vnet.net> <fsa5d2$abo$1@smc.vnet.net>
 
On 25 Mar, 06:17, ragfield <ragfi... at gmail.com> wrote:
> On Mar 23, 1:00 am, Karen Bindash <KarenBind... at googlemail.com> wrote:
>
> > Does that make sense? Any ideas how to pass arbitrary data to a C
> > program?
>
> You won't be able to do this directly.  You will have to write your
> own C function that converts the data from aMathematicatype to the
> raw data your function is expecting.  This is not very difficult.  Try
> something like this (not tested):
>
> /* MyFile.tm */
>
> :Begin:
> :Function: myFunc
> :Pattern: MyFunc[reals:(_Real...)]
> :Arguments: { reals }
> :ArgumentTypes: Manual
> :ReturnType: Manual
> :End:
>
But this makes nom sence to me, as my data is not necessarily going to
consist of real numbers. It might do, but I certainly dont wish to
assume thst.
> /* library function to call */
> extern int g(const double* theData, int theLength);
>
The function I am calling will have the prototype
int g (void *data, int length_of_data)
I did wonder if it should be treated as a collection of unsigned
characters, but I'm not sure if a Mathematica String would be
appropiate, as then characters like "\n" (new line) might have some
significance, which I dont want them to.