是否有必要在将可选参数传递给另一个可选参数之前进行检查? [英] Is it necessary to check an optional argument before passing it to another optional argument?

查看:89
本文介绍了是否有必要在将可选参数传递给另一个可选参数之前进行检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于可选参数的用法,我有以下问题.假设我在模块m_aaa

I have the following question concerning the usage of optional argument. Let's say I have the following routine aaa defined in module m_aaa

MODULE m_aaa
SUBROUTINE aaa(a, b)
  INTEGER           :: a
  INTEGER, OPTIONAL :: b
END SUBROUTINE
END MODULE

现在我有了第二个使用模块m_aaa的例程.是否可以像这样传递可选参数

now I have a second routine that uses the module m_aaa. Is it possible to pass the optional argument like this

! Variant 1:
SUBROUTINE bbb(c, d)
  USE m_aaa 
  INTEGER           :: c
  INTEGER, OPTIONAL :: d
  CALL aaa(c,d)
END SUBROUTINE  

或者是否有必要像下面这样检查可选参数d的存在:

or is it necessary to check the presence of the optional argument d like this:

! Variant 2:
SUBROUTINE bbb(c, d)
  USE m_aaa 
  INTEGER           :: c
  INTEGER, OPTIONAL :: d
  IF (PRESENT(d)) THEN
    CALL aaa(c,d)
  ELSE
    CALL aaa(c)
  ENDIF
END SUBROUTINE  

感谢您的帮助.

推荐答案

在将其作为实际参数传递给另一个可选的虚拟参数之前,不必检查是否存在可选的虚拟参数.

It is not necessary to check to presence of an optional dummy argument before passing it as an actual argument to another optional dummy argument.

12.5.2.12第4段(ISO/IEC 1539-1(2010年6月7日草案,又名Fortran 2008))对此提供了许可,涉及不存在的可选实际参数:

This is allowed by 12.5.2.12 paragraph 4 (ISO/IEC 1539-1 (Draft 7 June 2010) aka Fortran 2008) regarding optional actual arguments that are not present:

除了上面的列表中指出的以外,它可以作为与可选虚拟对象相对应的实际参数提供 论点,然后也将其视为不存在.

Except as noted in the list above, it may be supplied as an actual argument corresponding to an optional dummy argument, which is then also considered not to be present.

这篇关于是否有必要在将可选参数传递给另一个可选参数之前进行检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆