wmartin@ut-ngp.UUCP (Wiley Sanders) (11/07/86)
Here is a really perplexing bug in MacFortran 2.2. I was trying to write a simple program to calculate values of a poisson distribution, and dis- covered that, in passing values to an external function, the values were being trashed during the call to the external function, *regardless of whether the parameters were touched (equated) in the function*. I was trying to get the following program to work: C This program does not work C remove or comment out line 6 (the if/execute stmt) and it will work program tst real la integer j,m do 20 m=1,4 la=480./3600. j=24 if (m.EQ.-1) execute 'v2:MacFortran 2.2' write (9,fmt='(a,f14.2,2i20)') 'Bef Passing:',la,j,m write (9,fmt='(a,f14.2)') 'Val of bugger:',bugger(la,j,m) 20 write (9,fmt='(a,f14.2,2i20)') 'Aft Passing:',la,j,m pause execute 'v2:macFortran 2.2' end real function bugger(lambda,i,m) C just passes the factorial of the third parameter real lambda integer i,m write (9,100) 'bugger:',lambda,i,m 100 format(a,f14.2,3x,2i20) bugger=real(ifact(m)) return end integer function ifact(i) C Compute Factorial C Param - i Returns - i! integer i,k ifact=1 IF (i.EQ.0) return do 5 k=1,i 5 ifact=ifact*k return end The values of la,j, and m in the main program were always trashed upon returning from the function - but for the first time only! In addition I noted that, even though m was trashed, usually to some large integer, the program still counted the do loop correctly and called the function 4 times. After two days worth of messing around, changing random stuff here and there, lo and behold, upon removing line 6 (the if/execute line, a spurious line left over from a previous version of the program that didn't work either, but accepted keyboard input and was supposed to exit upon detecting an input value of -1), the following program was created. It runs fine and the values are not trashed! C This program works ok C comment out line 6 (the if/execute stmt) and it will work program tst real la integer j,m do 20 m=1,4 la=480./3600. j=24 C if (m.EQ.-1) execute 'v2:MacFortran 2.2' write (9,fmt='(a,f14.2,2i20)') 'Bef Passing:',la,j,m write (9,fmt='(a,f14.2)') 'Val of bugger:',bugger(la,j,m) 20 write (9,fmt='(a,f14.2,2i20)') 'Aft Passing:',la,j,m pause execute 'v2:MacFortran 2.2' end real function bugger(lambda,i,m) (EXACTLY the same as above) return end integer function ifact(i) (EXACTLY the same as above) return end I know that MacFortran is extraordinarily sensitive to nulls and other spurious characters that sometimes end up in a source file, but I looked at the first file with FEdit and there are none -the file is clean. What gives? Is MacFortran incapable of handling external functions? Anybody else have this problem? Someone should try clipping the first listing above and see is it works - maybe there is something wrong with my particular copy or something. Meanwhile, I will valiantly try to find a workaround, But it's kind of like trying to find a workwround when you add 2+2 and get 5. %*!&^&#*! -Wiley Sanders wmartin@ngp.UTEXAS.EDU