Initializing arrays, an advise is needed.
Lars Wirzenius
wirzeniu at klaava.Helsinki.FI
Wed May 8 02:38:40 AEST 1991
In article <1991May7.044811.27782 at cec1.wustl.edu> abed at saturn.wustl.edu (Abed M. Hammoud) writes:
> I have a program that calls a routine multiple times while
> running. Every time the routine get called it have to calculate
> samples of a function say sin(x) and fill an array of like
> n values long. where n, is the same during a given run.
One thing you could do is to have a static array inside your function
and compute its elements as needed. For example, if you function is
called foo:
void foo(int n) {
static int f[MAX_N] = { 1, 1 };
static int computed = 2;
while (computed <= n) {
f[computed] = f[computed-1] * computed;
++computed;
}
...
}
(This isn't quite your example, but I hope you get the idea.) Since 'f'
and 'computed' are static, they keep their values from one call to
another.
Lars Wirzenius wirzenius at cc.helsinki.fi
--
Lars Wirzenius wirzenius at cc.helsinki.fi
More information about the Comp.lang.c
mailing list