Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

functions

Status
Not open for further replies.

kostis1981

Programmer
Mar 17, 2007
6
GR
In my code i use a really big number of functions f,g,... which i define the following way:
Code:
real function f(a,b,c)
...
end function f
real function g(a,b,c)
...
end function g
.
.

Does anyone know a way to define these functions all together, in order to make my code shorter???
Thanx...
 
Code:
real function allinone(a,b,c,numberof)
... select operation by numberof ...
end
 
Could someone make it more clear??
How do i select the operation and how should my functions be named?? (i cant find any examples..)

thanx
 
What's a true problem? If you have functions f, g etc with different bodies, you must write that different bodies!
If these functions absolutely identical, so my question: why? No macroprocessors that can generate n functions with its own calculations for you...

If you have a function family with common body parts, you may write one with additional parameter (kind selector) as was shown in my post above, for example:
Code:
function f(x,n)
... parameters declarations ...
... common prelude then action selector:
select case(n)
case(1)
  ... special part #1
  f = x ! result
case(2)
  ... special part #2
  f = x + x
case default
  f = 3.14159*x
end select
end function f
Well, now you pack all calculations in the one function but is it better than 3 functions (identity, double and so on)? It depends of...

how should my functions be named??
It is a matter of taste...
 
Well the functions have all the same arguments...
But i dont want them to have the same name
I just want to define them all together in a subroutine file
separated from the main program.
 
Do you mean

Module 1 - main program
Code:
program main
!extern declarations for all the functions
 ...
stop
end
Module 2 - subroutine file
Code:
Function declarations
To link something like
Code:
ftncompiler -o executable module1.f95 module2.f95
 
The linking will vary from compiler to compiler. I'm just giving the g95 syntax. Your compiler might be different.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top