This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
MathLink C Function


is a MathLink type that describes a function pointer to a function taking an MLINK object as an argument and a MLYieldParameters object as an argument and returning an int.
  • Some MathLink API calls will block until data is available to read or space is available for writing. If an application needs to perform other useful processing during that blocking time, the application can install a yield function for the link and MathLink will automatically make calls to the yield function while it blocks.
  • To back out of a blocked read or write, the yield function should return a nonzero value.
  • The MLYieldParameters object is obsolete and is only maintained for backwards compatibility.
  • MLYieldFunctionObject is declared in the MathLink header file mathlink.h.
#include "mathlink.h"

int AppYieldFunction(MLINK lp, MLYieldParameters yp)
    /* ... */
    return 0;

int main(int argc, char **argv)
    MLENV env;
    MLINK link;
    int error;

    env = MLInitialize((MLParametersPointer)0);
    if(env (MLENV)0)
        { /* unable to initialize MathLink environment */ }

    link = MLOpenArgcArgv(env, argv, argv + argc, &error);
    if(link (MLINK)0 || error MLEOK)
        { /* unable to create the link */ }

    if(! MLSetYieldFunction(link, (MLYieldFunctionObject)AppYieldFunction))
        { /* unable to set the yield function for link */ }

    /* ... */

    return 0;