main function overview

The main function is defined in a C shared object (CSO). The definition of the main function returns an int data type and takes either no parameters or two parameters.

The following example shows the definition of a main function that returns an int and does not take any parameters:
    int main(void) { /* code for main */ }
The following example shows the definition of a main function that returns an int and takes two parameters.
    int main(int argc, char **argv) { /* code for main */ }
Where:
  • The int data type is set to the number of argument strings passed to the main function.
  • The char** data type is set to the vector of pointers to argument strings passed to main function.

The argc and argv parameter names are established by the C/C++ programming conventions.

The variables that are used with these parameters have the following restrictions:
  • argc >= 0
  • argv[argc] is a null pointer
  • argv[0] through argv[argc-1] point to NUL ('\0') and ends argument strings
  • argv[0] contains the shared object name if argc >= 0.