liveBook · Manning

Entry point

As explained in Modern C

An entry point is a program location at which execution of a function or other callable unit begins.

An entry point is a program location where execution of a function or other callable unit begins. In a C program, main is the entry point that connects the runtime system to the application. section 7.0 section 7.2

The C entry point

A portable C program implements one of two standard forms: int main(void); or int main(int argc, char* argv[argc+1]);. The prototype is prescribed by the C standard, but the function body is supplied by the programmer. Returning EXIT_SUCCESS or EXIT_FAILURE communicates execution status to the runtime system. Reaching the closing brace of main is equivalent to returning EXIT_SUCCESS. section 7.2

Important consequences follow from main's special role:

  • Use EXIT_SUCCESS and EXIT_FAILURE when returning from main; these are the status values guaranteed to work across platforms. section 7.2
  • Treat exit(s) as equivalent to evaluating return s in main: it terminates the program and never returns to its caller. section 7.2
  • Do not rely on platform-specific alternatives such as a void return type or an additional environment parameter when portability matters. section 7.2

Entry points below the C level

Assembler identifies fgoto with a label such as fgoto:, marking the machine-level entry point of that function. The surrounding instructions establish its stack frame and local storage before its translated body runs. section 13.5

int main(void);
int main(int argc, char* argv[argc+1]);


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":3}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":8}],[{\"line\":1,\"ch\":4},{\"line\":1,\"ch\":8}],[{\"line\":0,\"ch\":9},{\"line\":0,\"ch\":13}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":3}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":8}],[{\"line\":1,\"ch\":4},{\"line\":1,\"ch\":8}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":3}],[{\"line\":1,\"ch\":19},{\"line\":1,\"ch\":23}]]"}
!@%STYLE%@!

Compare the two standard main prototypes directly, including the command-line argument form. section 7.2

How Modern C covers it

How deep it goes
Explains standard main prototypes, termination status, exit behavior, and assembler labels, but stops short of runtime startup internals.
Examples
Uses the two standard main prototypes, EXIT_SUCCESS and EXIT_FAILURE, exit, and the fgoto assembler label.
What it assumes
Assumes basic C function familiarity while defining main, return status, exit, assembler labels, and stack setup in context.
What you can do after
Evaluate/understand which C main forms are portable and how assembler labels identify function entry locations.
How it connects
Connects entry points with functions, the C standard, the runtime system, program termination, assembler labels, and stack frames.

Also explained in

Compare how 10 books explain entry point →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.