Arguments to main

Top  Previous  Next

The standard declaration for a task’s main function is:

 

int main(int argc, char *argv[], char *envp[],

         CHAN * in_ports[], int ins,

         CHAN *out_ports[], int outs)

       

 

argc

number of command-line arguments. This is always zero for stand-alone tasks.

 

argv

command-line arguments

 

envp

always null

 

in_ports

vector of input ports

 

ins

number of entries in the vector in_ports

 

out_ports

vector of output ports

 

outs

number of entries in the vector out_ports

 

For example, a simple task might accept a stream of values on an input port representing characters, convert each character to upper case, and output the resulting stream of characters on an output port. The code for this is shown below; if you want to experiment you can find the source text in the file:

<3L>My Designs\examples\Sundance\example-2\upc.c.

 

#include <chan.h>

#include <ctype.h>

#include <stdio.h> // for EOF

 

main(int argc, char *argv[], char *envp[],

     CHAN * in_ports[], int ins,

     CHAN *out_ports[], int outs) {

 

   int c;

   for (;;) {

      chan_in_word(&c, in_ports[0]);

      if (c == EOF) break// terminate task

      chan_out_word(toupper(c), out_ports[0]);

   }

}