Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

Thanks so much for having a place for us propeller heads to hang out and chat.

Geography

Where in the world do Tek-Tips members come from?
GerritGroot (TechnicalUser)
11 Jun 12 10:49
Hi,

Using gfortran, if I have a code like

CODE

PROGRAM Test
IMPLICIT NONE
REAL :: y,MyFunc
y=MyFunc(2.)
WRITE(*,*)y
END PROGRAM Test

REAL FUNCTION MyFunc(x)
REAL, INTENT(IN) :: x
MyFunc=x**2
END FUNCTION MyFun

that works and another one like

CODE

PROGRAM Test
IMPLICIT NONE
REAL :: MyFunc
WRITE(*,*)MyFunc(2.)
END PROGRAM Test

REAL FUNCTION MyFunc(x)
REAL, INTENT(IN) :: x
MyFunc=x**2
END FUNCTION MyFun

That doesn't work. What can be the cause?
(In the example they both work btw, but the second option in my code causes gfortran's executable to get stuck in a sort of endless loop)

Thanks,

Gerrit

(My reaction may be slow this week, lots of meetings and so on..)
melmacianalf (TechnicalUser)
11 Jun 12 11:38
Seems like it has to do with recursive input/output. Not sure how well this is supported by gfortran. Your simple example works with gfortran. Can you post some example which can reproduce the "... in a sort of endless loop"
melmacianalf (TechnicalUser)
11 Jun 12 11:49
BTW, which version of gfortran creates the problem? Did u enable optimization?
salgerman (Programmer)
11 Jun 12 12:58
First of all, there is a typo at the end of the function....the function name's got a missing 'c'.

Second, What happens if you enclose your function call in a set of parenthesis, you know, the one after the WRITE statement? Does it make a difference?

I use g95 and the program works just fine...but I seem to recall some problem along time ago, either in fortran or something else and I thought I had something to do with evaluation on the spot, where I couldn't "write(*,*) myfun(3)+3" but I could "write(*,*) (myfun(3)+3)" and I figure the parenthesis were helping in including another evaluation layer BEFORE handing over the result to the write statement.

my 2 cents
FJacq (Programmer)
11 Jun 12 13:08
Your program is perfect if you don't use IO statement within the function.

It exits other limitations with non pure function, like modifying a global variable itself used in the write statement calling the function, but this is rather rare.

François Jacq

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close