[Fortran] Functions Calling in Subroutines

  • Fortran
  • Thread starter Raghnar
  • Start date
  • #1
41
1
There are some caveat in fortran 77 while calling functions inside subroutines?
I have some weird errors while calling a function inside a subroutine, e.g. Segmentation Fault while using/writing the argument of the function (but not sooner, I can still do an "Hallo World"!) or starting a do loop.
The function receive a Complex and an integer argument. printing the first complex variable get you 0 whatever the input is, printing the integer variable goes in segmentation fault... there are some memory usage issues, but I don't really know where to look...
This is only inside a subroutine, before calling the subroutin everything works just fine.

Any suggestions?
 
Last edited:

Answers and Replies

  • #2
jtbell
Mentor
15,615
3,639
Can you post a short but complete (compilable) program that illustrates the problem?
 
  • #3
41
1
I will try to reproduce the program in a short version, seeing if the problem is still there... The one which I use is far too complicated
 
  • #4
AlephZero
Science Advisor
Homework Helper
6,994
291
Make sure your function is defined as the correct type of variable, inside the subroutine where you call it.

complex function c(x,y)
real x, y
... do some calculations
c = something
return
end

subroutine s
real x, y
complex z
complex c
...
z = c(x,y)
...
end

If you omit the "complex c" statment inside the subroutine, the compiler will assume that function c returns a REAL value. That certainly won't work properly, and may give you segementation faults etc.
 
  • #5
41
1
That was the problem, thank you!! :)
 

Related Threads on [Fortran] Functions Calling in Subroutines

Replies
3
Views
677
Replies
8
Views
2K
Replies
4
Views
37K
Replies
0
Views
2K
Replies
2
Views
658
  • Last Post
Replies
3
Views
2K
Replies
10
Views
6K
Replies
6
Views
4K
Replies
0
Views
2K
Top