6.2.4 Storage durations of objects

Previous Table of Contents "New C Standard" commentary

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

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

450 Allocated storage is described in 7.20.3.

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

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

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

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

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

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

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

458 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.

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

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

461 The initial value of the object is indeterminate.

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

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

464 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)

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

466 The initial value of the object is indeterminate.

467 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).

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

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

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

471 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: 2008-01-30 02:39:40 The text from WG14/N1256 is copyright © ISO