A89: Just subscribed... my first question


[Prev][Next][Index][Thread]

A89: Just subscribed... my first question




I read in one of the archives that using static variables in TI-GCC makes
the program smaller. Could someone explain this? As far as I know, static
has 2 meanings in C:

1. When used to modify a local variable, specifies that the variable is to
have static duration. This means it is allocated when the program begins and
deallocated when the program finishes. A variable declared as static in a
function will retain it's value across function calls:

int inc(void)
{
    static int i = 0; /*initialization occurs on the first call only*/
    return ++i;
}

inc will return 1 the first time it is called, 2 the second time it is
called, and so on.

Variables that are not declared with a specific storage class modifier
(static, register, extern) are assumed to be auto. auto declared variables
are allocated when program execution reaches the block in which they are
declared and deallocated when that block finishes.

2. When used to modify global variables, static specifies that the variable
has file scope and exists only in the file in which it is declared. This is
not useful in TI-GCC, since mutiple source files is not supported.

So basically, I don't understand how static, as opposed to auto could affect
the file size. Can anyone elaborate?

-Kevin