Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uwm.edu!ux1.cso.uiuc.edu!phil From: phil@ux1.cso.uiuc.edu (Phil Howard KA9WGN) Newsgroups: comp.lang.c Subject: Re: Initializing arrays, an advise is needed. Message-ID: <1991May7.234600.28045@ux1.cso.uiuc.edu> Date: 7 May 91 23:46:00 GMT References: <1991May7.044811.27782@cec1.wustl.edu> Organization: University of Illinois at Urbana Lines: 30 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. > My question is, is there a way to initialize the elements of > the array in something like > float a[n] = { sin(a0), sin(a1), ....., sin(a(n-1)) } I assume from one run to the next, n can be different, and n is also passed as part of the arguments to your function anyway. I also assume n == 0 is not a valid condition. Define a static integer internal to the subroutine and initialize it to 0. I'll refer to it as k. When the subroutine is entered, compare the incoming n to k. If they are the same, go on... the table is initialized. If they are not the same, assert that k == 0 && n != 0, and if ok, execute the code to initialize the table and fall through to do the deed for this first function call as above. -- /***************************************************************************\ / Phil Howard -- KA9WGN -- phil@ux1.cso.uiuc.edu | Guns don't aim guns at \ \ Lietuva laisva -- Brivu Latviju -- Eesti vabaks | people; CRIMINALS do!! / \***************************************************************************/