Skip to content

Latest commit

 

History

History
29 lines (19 loc) · 1.91 KB

cpp-program-startup-and-termination.md

File metadata and controls

29 lines (19 loc) · 1.91 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: C++ Program Startup and Termination
C++ Program Startup and Termination
11/04/2016
C++ Standard Library, program startup and termination
terminating execution
Function Main procedures
control text streams
startup code, and C++ program termination
main function, program startup
f72c8f76-f507-4ddd-a270-7b60f4fed625

C++ Program Startup and Termination

A C++ program performs the same operations as a C program does at program startup and at program termination, plus a few more outlined here.

Before the target environment calls the function main, and after it stores any constant initial values you specify in all objects that have static duration, the program executes any remaining constructors for such static objects. The order of execution is not specified between translation units, but you can nevertheless assume that some iostreams objects are properly initialized for use by these static constructors. These control text streams are:

  • cin — for standard input.

  • cout — for standard output.

  • cerr — for unbuffered standard error output.

  • clog — for buffered standard error output.

You can also use these objects within the destructors called for static objects, during program termination.

As with C, returning from main or calling exit calls all functions registered with atexit in reverse order of registry. An exception thrown from such a registered function calls terminate.

See also

C++ Standard Library Overview
Thread Safety in the C++ Standard Library