User`s manual

Dynamic C Users Manual digi.com 63
type
Whichever keyword (cofunc or scofunc) is used is followed by the data type returned (void, int,
etc.).
name
A name can be any valid C name not previously used. This results in the creation of a structure of type
CoData of the same name.
dim
The cofunction name may be followed by a dimension if an indexed cofunction is being defined.
cofunction arguments (arg1, . . ., argN)
As with other Dynamic C functions, cofunction arguments are passed by value.
cofunction body
A cofunction can have as many C statements, including abort, yield, waitfor, and waitfordone
statements, as needed. Cofunctions can contain calls to other cofunctions.
5.5.2 Calling Restrictions
You cannot assign a cofunction to a function pointer then call it via the pointer.
Cofunctions are called using a waitfordone statement. Cofunctions and the waitfordone statement
may return an argument value as in the following example.
The keyword waitfordone (can be abbreviated to the keyword wfd) must be inside a costatement or
cofunction. Since a cofunction must be called from inside a wfd statement, ultimately a wfd statement
must be inside a costatement. If only one cofunction is being called by wfd the curly braces are not
needed.
The wfd statement executes cofunctions and firsttime functions. When all the cofunctions and
firsttime functions listed in the wfd statement are complete (or one of them aborts), execution pro-
ceeds to the statement following wfd. Otherwise a jump is made to the ending brace of the costatement or
cofunction where the wfd statement appears and when the execution thread comes around again control is
given back to wfd.
In the example above, x, y and z must be set by return statements inside the called cofunctions. Exe-
cuting a return statement in a cofunction has the same effect as executing the end brace. In the example
above, the variable k is a status variable that is set according to the following scheme. If no abort has taken
place in any cofunction, k is set to 1, 2, ..., n to indicate which cofunction inside the braces finished exe-
cuting last. If an abort takes place, k is set to -1, -2, ..., -n to indicate which cofunction caused the abort.
int j,k,x,y,z;
j = waitfordone x = Cofunc1;
k = waitfordone{ y=Cofunc2(...); z=Cofunc3(...); }