Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!dewey.soe.berkeley.edu!oster From: oster@dewey.soe.berkeley.edu (David Phillip Oster) Newsgroups: comp.sys.mac.programmer Subject: Re: Initializing automatic arrays Keywords: MPW-C, LSC, versions 3.0 Message-ID: <28295@ucbvax.BERKELEY.EDU> Date: 5 Mar 89 21:46:46 GMT References: <9226@orstcs.CS.ORST.EDU> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) Distribution: na Organization: School of Education, UC-Berkeley Lines: 36 In article <9226@orstcs.CS.ORST.EDU> sagen@nucthy.physics.orst.edu (Milt Sagen) writes: _>#ifdef THINK_C _>#define real double _>#else _>#define real extended _>#endif _> _>real XFactorial( x ) _> real x ; _>{ _> real coef[] = ( 76.18009173, -86.50532033, 24.01409822 _> -1.231739516, 0.120858003e-2, 0.536382e-5 ) ; _>} this program has numerous errors, and certainly doesn't do what the author intended. Notice that Milt uses parentheses to delimit his list of constants: That makes the whole thing be a constant expression that returns its last component as its value. So, what he has is equivalent to real coef[1] = 0.536382e-5; Note further that even if he had used squiggly braces, there is a comma missing at the end of the first line, so he will get a 5 element array of which coef[2] == 24.01409822 - 1.231739516; The following version version is more correct: real XFactorial( x )real x;{ static real coef[] = { 76.18009173, -86.50532033, 24.01409822, -1.231739516, 0.120858003e-2, 0.536382e-5 } ; } This version is correct if, as is likely, coef will not change at runtime. I am surprised that MPW C passed the original without complaint. I like compilers to point out errors in my code. --- David Phillip Oster --"When we replace the mouse with a pen, Arpa: oster@dewey.soe.berkeley.edu --3 button mouse fans will need saxophone Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu --lessons." - Gasee