[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: "static <type> <varname>;" like C in lua?
- From: Sean Conner <sean@...>
- Date: Mon, 17 Mar 2014 23:51:51 -0400
It was thus said that the Great email@example.com once stated:
> Is there anything in lua like what is available in C:
> static int counter:
> (where "int" and "counter" are examples to satisfy the
> syntax and are not part of the question...;)
In what context? Because "static" has meaning depending upon where it
static int counter; /* 1 */
static int foo(void) /* 2 */
static int bar; /* 3 */
1. counter has file scope---it's only visible to the file its defined
in, and can't be seen by other compilation units (files). Its
symbol does not appear in the resulting object or executable file
2. This is identical to 1, except for a function, not a variable.
3. In this context, "static" means "persistent storage." The variable
"bar", only visible in function foo(), exists for the lifetime of
the program, not the function, and thus, its contents will remain
across multiple calls to foo().
 With the possible exception of a special "debug" mode for the
comiler/linker, but that's system dependent.