Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!sdd.hp.com!think.com!rpi!uupsi!sunic!fuug!news.funet.fi!hydra!klaava!klaava!wirzeniu From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) Newsgroups: comp.lang.c Subject: Re: Initializing arrays, an advise is needed. Message-ID: <1991May7.163840.629@klaava.Helsinki.FI> Date: 7 May 91 16:38:40 GMT References: <1991May7.044811.27782@cec1.wustl.edu> Sender: news@klaava.Helsinki.FI (Uutis Ankka) Organization: University of Helsinki Lines: 29 In article <1991May7.044811.27782@cec1.wustl.edu> abed@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@cc.helsinki.fi -- Lars Wirzenius wirzenius@cc.helsinki.fi