auto Automatic Data Storage Class
The automatic class specifies that an object is to be created
dynamically. The auto keyword may only be used internal to a
function. An auto variable is created on the run-time stack when its
parent function is invoked, and it is destroyed when that function
exits. An auto object has temporary life, and its scope is limited to
the block in which it is declared and all subordinate blocks (if
any).
[auto] [type] identifier [[= initializer], ... ] ;
Notes: The initial value of an auto variable is undefined if it
is not explicitly initialized, either in the initializer
list or via assignment. The initializer expression can
be any valid run-time expression, including function
calls. Note that auto arrays, structures, and unions may
not have initializer lists.
Since C permits declarations to occur at the beginning of
any block (or compound statement), it is possible to use
the same identifier for two different variables at
different block levels. This is generally construed as a
bad programming practice. While execution proceeds in
the inner block, the identifier of the same name in the
outer block is hidden.
Since the auto class is the default class for all
internal variable declarations, the keyword auto is very
rarely specified. If the type is omitted and auto is
specified, type int is assumed.
Formal arguments in a function definition that have no
class keyword are treated like automatic variables.
Excess register variables are treated as if they had
class auto.
Since the execution path of a program may vary from run
to run, the amount of stack space needed for auto
variables will vary accordingly.
-------------------------------- Example ---------------------------------
auto int max = 1234;
auto struct date today;
double average; /* defaults to auto */
auto int i = f(1234) + 10;
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster