main
A user-supplied function where NLM execution begins
- Local Servers:blocking
- Remote Servers:N/A
- Classification:ANSI
- Service:Thread
Syntax
#include <nwthread.h>
int main (
int argc,
const char *argv []);
int main (void);
void main (
int argc,
const char *argv []);
void main (void);
Parameters
- argc
- (IN) Specifies the number of arguments on the command
line.
- argv
- (IN) Points to the array of command line arguments
pointers.
Syntax
The syntax for the main function can be any of the following:
Return Values
Currently, the return code from main is ignored.
Remarks
The main function is a user-written function that is executed
as the initial thread of the NLM.
Prior to the main function receiving control, the _Prelude
function (in PRELUDE.OBJ) does the following:
- The current connection is set to 0
and a unique task number is allocated.
- A new screen is created. The screen name is the
name specified by the linker directive SCREENNAME. If the screen
name is not specified, the description text specified in the FORMAT
directive is used as the screen name. If the screen name is "none,"
"default," or "System Console," no new screen is created.
- A new thread is started with the specified stack
size. If no stack size is specified, then the default stack size
(8192 bytes) is used.
- The thread’s name is the name specified
by the linker directive THREADNAME. The thread name can be up to
16 characters long. The first thread name is generated by appending
"0" to the specified thread name, the second by appending "1", and
so on. If the thread name is not specified, the name specified with
the linker directive NAME (with .NLM appended) is used as the pattern
for generating thread names.
- If the main function returns with a return code
of rc, it is equivalent to its executing ExitThread (EXIT_THREAD,
rc). See the discussion of the ExitThread function.
- The command line to the program is assumed to be
a sequence of tokens separated by blanks. The tokens are passed
to the main function as an array of pointers to character strings
in the argv parameter. The first element of argv is
a pointer to a character string containing the program name, including
the full path. The last element of the array pointed to by argv is
a NULL pointer ( argv[argc] is
NULL). Arguments that contain blanks can be passed to the main function
by enclosing them within double quote characters (which are removed
from that element in the argv vector).
The command line can also be obtained in its original format
by using the getcmd function.
Example
#include <nwthread.h>
int main (int argc, char *argv[])
{
/* Do the work */
.
.
.
/* Terminate thread and NLM */
return 0;
}