Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>static static data storage class</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
static                   Static Data Storage Class

    When used with a variable, the static class specifies that an object
    is to exist for the life of the program.  The static keyword may be
    used both internal and external to a function.  A static variable
    retains its value across function calls, unlike an auto variable
    which is reinitialized each time its parent function is called.  A
    static variable has permanent life, and its scope is limited to the
    block in which it is declared, and all subordinate blocks (if any).
    The scope of static externals is from the point of declaration
    through the end of the source code file.  The format of a declaration
    that specifies register class is:

           static [type] identifier [[= initializer], ... ] ;

    When used with a function definition, the static class restricts that
    function name's visibility such that that function can only be called
    by name from functions defined in the same source code file.  The
    format of such a definition is:

          static [type] function-name ([argument-list])

      Notes:    The initializer value must be a compile-time constant.
                Scalars, arrays, structures and unions may have
                initializer lists.  If no initial value is specified, it
                defaults to zero, cast in the object's type.  In the case
                of an array or structure, each element or member is set
                to zero.

                Since auto arrays, structures and unions may not have
                initializer lists, you can change their class to static
                when you need to use initializer lists.

                A static function is useful when you have a group of
                functions in a file that you want to restrict access to.
                By declaring the functions static, the user cannot call
                them directly from another file; further, he may have
                internal or external names of the same spelling without
                conflict. The benefits are similar for external static
                data--in this case, you can share data, but it is
                protected from functions outside the file.

                If the type is omitted, int is assumed.

  -------------------------------- Example ---------------------------------

           static int max = 1234;
           static struct date today = {87, 5, 1};

           static int testchar()
           {.                             static int i;
                static char name[] = "abcdef";
                ...
           }

See Also: Classes auto enum

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson