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
  • Subject: [mg89652] Re: a mathlink question
  • From: Jens-Peer Kuska <kuska at>
  • Date: Mon, 16 Jun 2008 06:41:18 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <g32q5m$c2t$>
  • Reply-to: kuska at


something like:

#include "mathlink.h"

static int prev=0;

void add_to_previous_sum(int x) {
   return prev;

:Function: add_to_previous_sum
:Pattern: AddToPreviousSum[x_Interger]
:Arguments: {x}
:ArgumentType: {Integer}
:ReturnType: Integer

int main(int argc, char *argv[]) {
   return MLMain(argc,argv);


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?
> Thanks.
> GS.

  • Prev by Date: minor progress with 6.0 Documentation
  • Next by Date: Re: Gradient fill as Background for Plot
  • Previous by thread: Re: a mathlink question
  • Next by thread: Re: a mathlink question