i’m not exactly sure how? my understanding is from the K&R book. if what you
are saying is true, i’m not sure exactly how this works :
~/eg/c > cat static.c
#include <stdlib.h>
#include <stdio.h>
void
foo (void)
{
static int count = 0;
printf (“%s called %d times\n”, FUNCTION, count++);
}
void
bar (void)
{
static int count = 0;
printf (“%s called %d times\n”, FUNCTION, count++);
}
~/eg/c > cat main.c
extern void foo (void);
extern void bar (void);
int
main (argc, argv, env)
int argc;
char **argv;
char **env;
{
int i;
for (i = 0; i < 4; i++)
{
foo ();
bar ();
}
return 0;
}
~/eg/c > gcc main.c static.c && a.out
foo called 0 times
bar called 0 times
foo called 1 times
bar called 1 times
foo called 2 times
bar called 2 times
foo called 3 times
bar called 3 times
this looks like the two counts are made ‘private’ to foo and bar, and also
that the scope is not global, although i realize that allocation in the data
segment might be what you meant by ‘global’. i was referring to their scopes,
which certainly seem not to be global. i have a feeling you will insert a
reason that i am wrong,
here →
in any case, a ruby ‘static’ could be similar in meaning if not in
implimentation. perhaps this is more difficult than i realize to impl.
in any case it seems like it would be usefull to have this ability if not
the syntax (no one ever likes my syntax ideas
).
-a
···
On Tue, 4 Feb 2003, Yukihiro Matsumoto wrote:
Hi,
In message “Re: ruby-dev summary 19437-19455” > on 03/02/04, ahoward ahoward@fsl.noaa.gov writes:
C’s static is global that extent is limited to enclosing block (or file).
I don’t think it’s what we want.
static int count = 0; // <-- THIS STATIC
I know. It’s still global with constant initializer.
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================