Variables with automatic storage duration include:
• local variables declared in functions
• function parameters
• local variables or function parameters declared with register
Such variables are created when program execution enters the block in which they’re defined, they exist while the block is active and they’re destroyed when the program exits the block. An automatic variable exists only in the nearest enclosing pair of curly braces within the body of the function in which the definition appears, or for the entire function body in the case of a function parameter. Local variables are of automatic storage duration by default. For the remainder of the text, we refer to variables of automatic storage duration simply as automatic variables.
Performance Tip 6.1
Automatic storage is a means of conserving memory, because automatic storage duration variables exist in memory only when the block in which they’re defined is executing.
Software Engineering Observation 6.5
Automatic storage is an example of the principle of least privilege. In the context of an application, the principle states that code should be granted only the amount of privilege and access that it needs to accomplish its designated task, but no more. Why should we have variables stored in memory and accessible when they’re not needed?
Good Programming Practice 6.4
Declare variables as close to where they’re first used as possible.
3.144.227.9