[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "static <type> <varname>;" like C in lua?
- From: meino.cramer@...
- Date: Tue, 18 Mar 2014 05:04:02 +0100
Sean Conner <sean@conman.org> [14-03-18 04:56]:
> It was thus said that the Great meino.cramer@gmx.de once stated:
> > Hi,
> >
> > 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
> appears.
>
> 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
> [1].
>
> 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().
>
> -spc
>
> [1] With the possible exception of a special "debug" mode for the
> comiler/linker, but that's system dependent.
>
Hi Sean,
sorry for being inexact...
I am in search of a way to create a variable in the scope of a
function which is persistent i.e. does not loose it content over
several calls of its funtion.
best regards,
mcc