Automatically transform or expand do loop in a subroutine



Hi All,

I knew following piece of code will not be compiled, at least with
Compaq Visual Fortran. My intention of this code is to let the
compiler automatically transform or expand the loop inside the
function (I do not care the code size) if the caller has a SMALL
CONSTANT integer 'd' in its argument list when the compiler is doing
optimization. Because the function is really crucial for the
performance, I want to save computing time as much as I can. So do not
ask me why I want to do this. Actually I guess this idea is similar as
the template in C++.

Are there any ways to implement this idea easily with Fortran?

Thanks!

--------------------------------------------------------------------------
program main

integer :: e, c
e = ad(c, 10)

stop
end program main

integer function ad(c,d)
implicit none
integer :: c
integer, parameter :: d
integer :: i
do i=1,d
c = c + i
end do
ad = c
return
end function
.