由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Computation版 - 再问个Fortran得问题
相关主题
问个fortran和python编程的问题Re: fortran subroutine and function
a question about mpi-fortran偶也问一fortran问题
problem about Fortran 77 in unixFortran code optimization
请教一个程序调用问题(FORTRAN DLL),谢谢!MPI Write?
问个matlab function handle的问题[转载] 问一个fortran的问题
[合集] 有关fortran返回数组的问题!Fotran77程序的移植问题
Fortran里面哪个函数显示系统时间?Problems about Mex-file to call Fortran
help on interface for Matlab and Fortranfortran的random number 相关的函数lib是啥?
相关话题的讨论汇总
话题: func话题: fortran话题: functions话题: function话题: subroutine
进入Computation版参与讨论
1 (共1页)
l*****s
发帖数: 774
1
subroutine和子函数function有什么区别?
感觉subroutine比子函数function用起来方便不少?
是不是这样得?
t*******y
发帖数: 637
2
确实方便一些
一般用subroutine用的多得多吧

【在 l*****s 的大作中提到】
: subroutine和子函数function有什么区别?
: 感觉subroutine比子函数function用起来方便不少?
: 是不是这样得?

t***l
发帖数: 533
3
一般复杂的用subroutine,
简单的用function。
对于返回简单值,频繁使用的时候
function用起来简单一点

【在 l*****s 的大作中提到】
: subroutine和子函数function有什么区别?
: 感觉subroutine比子函数function用起来方便不少?
: 是不是这样得?

O******e
发帖数: 734
4
There are some differences.
Since functions can be invoked in-line, functions with side-effects are not
allowed to be used in certain ways. Metcalf and Reid give two examples on
page 83 in Fortran 90/95 Explained, which are basically:
! func(z) might not be evaluated if x > y, so if func(z) normally modifies z,
! the value of z is undefined after execution of the following statement
x > y .or. func(z)
! since the order in which func(x,y) and func(y,x) are evaluated must not
! matter, func() m

【在 l*****s 的大作中提到】
: subroutine和子函数function有什么区别?
: 感觉subroutine比子函数function用起来方便不少?
: 是不是这样得?

t*********r
发帖数: 8
5
These are actually pitfalls of fortran functions.
Good programming is that you should NOT modify the arguments of a function.
Whereas fortran allows you to do that, you should NOT.

not
z,

【在 O******e 的大作中提到】
: There are some differences.
: Since functions can be invoked in-line, functions with side-effects are not
: allowed to be used in certain ways. Metcalf and Reid give two examples on
: page 83 in Fortran 90/95 Explained, which are basically:
: ! func(z) might not be evaluated if x > y, so if func(z) normally modifies z,
: ! the value of z is undefined after execution of the following statement
: x > y .or. func(z)
: ! since the order in which func(x,y) and func(y,x) are evaluated must not
: ! matter, func() m

c****w
发帖数: 565
6
something called 'interface'...

【在 t*********r 的大作中提到】
: These are actually pitfalls of fortran functions.
: Good programming is that you should NOT modify the arguments of a function.
: Whereas fortran allows you to do that, you should NOT.
:
: not
: z,

O******e
发帖数: 734
7
I agree it is not good practice.
Out of curiosity I tried using functions with side effects in those two
examples given by M&R, and even declared explicit function interfaces
to tell the compiler about the intent(inout) arguments. The Intel compiler
does not detect the problem, and gives different values if I reverse the
two function calls in the max() example.

【在 t*********r 的大作中提到】
: These are actually pitfalls of fortran functions.
: Good programming is that you should NOT modify the arguments of a function.
: Whereas fortran allows you to do that, you should NOT.
:
: not
: z,

t*********r
发帖数: 8
8
en. i just did similar tests on a Mac with xlf, on an XD1 with pgf and on an
Altix with ifort.
i put the func in a module.
as expected, the compilers don't complain; however they don't do what you '
intend' to do.
the executables from ifort and xlf gives one result, the executables from
pgf gives another!

compiler

【在 O******e 的大作中提到】
: I agree it is not good practice.
: Out of curiosity I tried using functions with side effects in those two
: examples given by M&R, and even declared explicit function interfaces
: to tell the compiler about the intent(inout) arguments. The Intel compiler
: does not detect the problem, and gives different values if I reverse the
: two function calls in the max() example.

O******e
发帖数: 734
9
I usually make my functions explicitly pure or elemental anyway,
so as you mentioned, free of side effects. Then there are no
such pitfalls to worry about.

an

【在 t*********r 的大作中提到】
: en. i just did similar tests on a Mac with xlf, on an XD1 with pgf and on an
: Altix with ifort.
: i put the func in a module.
: as expected, the compilers don't complain; however they don't do what you '
: intend' to do.
: the executables from ifort and xlf gives one result, the executables from
: pgf gives another!
:
: compiler

1 (共1页)
进入Computation版参与讨论
相关主题
fortran的random number 相关的函数lib是啥?问个matlab function handle的问题
发现一个有趣的事情,关于fortran IMSL library[合集] 有关fortran返回数组的问题!
请教fortran debugerFortran里面哪个函数显示系统时间?
Fortran里面子程序用END和END SUBROUTINE结尾有什么区别?help on interface for Matlab and Fortran
问个fortran和python编程的问题Re: fortran subroutine and function
a question about mpi-fortran偶也问一fortran问题
problem about Fortran 77 in unixFortran code optimization
请教一个程序调用问题(FORTRAN DLL),谢谢!MPI Write?
相关话题的讨论汇总
话题: func话题: fortran话题: functions话题: function话题: subroutine