Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to call only one function, use a command line parameter which you get via argv/argc.</p> <pre><code>int main(int argc, char *argv[]) { if (argc != 2) return -1; // zero or 2+ commandline arguments if (0 == strcmp(argv[1], "function1")) function1(); else if (0 == strcmp(argv[1], "function2")) function2(); else { return -1; /* error */ } return 0; } </code></pre> <p>What happens behind the scenes (before main() is called), a partial list:</p> <ul> <li>OS creates new prrocess and executes it's entry point address (not main()).</li> <li>Entry point function receives all command line arguments from the OS in some OS dependent manner.</li> <li>Various C std library are called to initialize the framework.</li> <li>Environment variables are copied to std C library structures.</li> <li>Dependent DLL's are loaded.</li> <li>Globals are initialized.</li> <li>An array of char* is created (argv). Each array entry points to a C string. The first (argv[0]) is always the exe name. If the OS/shell have passed command line arguments, they are copied to argv[1], argv[2], etc.</li> <li>main(int, char**) is called with argv and argc.</li> </ul> <p>All this work is done to abstract the OS from the program. The above flow is heavily OS dependent and doesn't interest most developers. When you're an (very) advanced C programmer or if you take an interest in this flow then you can read on your own.</p> <p>main() prototype is defined by the C standard. Actually there are several legal prototypes to choose from. The compiler/linker will choose what you implement.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload