6.2.4 Storage durations of objects

Previous Table of Contents

445 An object has a storage duration that determines its lifetime.

446 There are three storage durations: static, automatic, and allocated.

447 Allocated storage is described in 7.20.3.

448 The lifetime of an object is the portion of program execution during which storage is guaranteed to be reserved for it.

449 An object exists, has a constant address,25) and retains its last-stored value throughout its lifetime.26)

450 If an object is referred to outside of its lifetime, the behavior is undefined.

451 The value of a pointer becomes indeterminate when the object it points to reaches the end of its lifetime.

452 An object whose identifier is declared with external or internal linkage, or with the storage-class specifier static has static storage duration.

453 Its lifetime is the entire execution of the program and its stored value is initialized only once, prior to program startup.

454 An object whose identifier is declared with no linkage and without the storage-class specifier static has automatic storage duration.

455 For such an object that does not have a variable length array type, its lifetime extends from entry into the block with which it is associated until execution of that block ends in any way.

456 (Entering an enclosed block or calling a function suspends, but does not end, execution of the current block.)

457 If the block is entered recursively, a new instance of the object is created each time.

458 The initial value of the object is indeterminate.

459 If an initialization is specified for the object, it is performed each time the declaration is reached in the execution of the block;

460 otherwise, the value becomes indeterminate each time the declaration is reached.

461 For such an object that does have a variable length array type, its lifetime extends from the declaration of the object until execution of the program leaves the scope of the declaration.27)

462 If the scope is entered recursively, a new instance of the object is created each time.

463 The initial value of the object is indeterminate.

464 Forward references: statements (6.8), function calls (6.5.2.2), declarators (6.7.5), array declarators (6.7.5.2), initialization (6.7.8).

465 25) The term “constant address” means that two pointers to the object constructed at possibly different times will compare equal.

466 The address may be different during two different executions of the same program.

467 26) In the case of a volatile object, the last store need not be explicit in the program.

468 27) Leaving the innermost block containing the declaration, or jumping to a point in that block or an embedded block prior to the declaration, leaves the scope of the declaration.

Next

Created at: 2005-06-29 02:18:54 The text from WG14/N1124 is copyright © ISO