Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: a mathlink question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89659] Re: a mathlink question
  • From: Albert Retey <awnl at arcor.net>
  • Date: Mon, 16 Jun 2008 06:42:42 -0400 (EDT)
  • References: <g32q5m$c2t$1@smc.vnet.net>

GS wrote:
> I would like to call a C-program from Mathematica. All the examples in
> the MathLink tutorials (like AddTwo[i,j]) work like this: they are
> called from Mathematica, are executed, send the result to Mathematica
> and exit.
> 
> I would like a C-program to not exit after the execution, and keep the
> memory of the previous inputs. Say, I want an external C-program, to
> be called as AddToPreviousSum[x]. When it is first called, it returns
> x. When it is called the second time AddToPreviousSum[y], it returns x
> +y. When it is called the third time AddToPreviousSum[z], it returns x
> +y+z, and so on.
> 
> How do I implement this in C using MathLink?

Nothing special to do here, just don't think that MathLink is about
running programms written in C but about including libraries of
functions written in C which can be accessed from within Mathematica. In
your C-Library you can do everything that you can do in C, e.g. use a
global variable to store the sum of all calls in your example. You can
also supply more than just one function per file/library, so you could
also provide functions to reset the sum. Otherwise only when you do a
Reinstall ( = Uninstall + Install ) the library is reloaded and the
global variable is reset. I haven't tried this and haven't done any
MathLink programming for a while but hope that I still remember this
correctly...

hth,

albert


  • Prev by Date: Re: Nested Grids
  • Next by Date: Re: Nested Grids
  • Previous by thread: Re: a mathlink question
  • Next by thread: Re: a mathlink question