Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29276 Discussions

Passing non existing optional parameters to functions

ingo_berg
Beginner
598 Views
Hi everybody,

I have a generic function ite which stands for "if ... then ... else". It is similar to C++ conditionals like "(Stat) ? a : b".

I would like to set the content of a variable dependant on the existance of an optional parameter. The code snippet looks like this:

a_iRngMin = ite(present(a_iIntMin), a_iIntMin, 0)

Where a_iIntMin is an optional integer variable in a subroutine. My question is now: Is it safe to pass a non existing optional parameter to a function if I can guarantee not to use it within that function?

I'd like to know how the intel compiler handles such stuff.
0 Kudos
4 Replies
Steven_L_Intel1
Employee
598 Views
Yes, it is supposed to be safe to do that. There needs to be an explicit interface for the routine you are calling that indicates the argument is OPTIONAL. The compiler is supposed to do its own "PRESENT" test and pass an "omitted" argument through. We have had bugs in this area, though primarily when calling intrinsics, so I can't guarantee it will work. It should, though.

In your example, you don't even need the present() in the call, as the ite function can do its own test. Amazing stuff, eh?
0 Kudos
ingo_berg
Beginner
598 Views
So I should be able to write a function like:

set_if_present(a_iParam, iVal)

This is something I originally wanted to do but did'nt expect to be possible. I will try it, would be nice if it works.

Ingo
0 Kudos
Steven_L_Intel1
Employee
598 Views
Yes, you should be able to do that.
0 Kudos
onejeanster
Beginner
598 Views
Message for Ingo Berg from
Trevor Henn. Contact him at:
Message Information from:
___________________________
----------------------------------------------------
Forum: Namibia Travel
Thread Number: 89
Reply Number: 5 (0 = original message)
Thread Subject: Looking for Ingo Berg
Posted by Trevor Henn
Posted on 19:45:40, 01/15/2005
----------------------------------------------------
Posted Message:
----------------------------------------------------
HiI hope someone can assist me.
I am looking for my long lost surfer buddy Ingo Berg.We worked together in RSA on the Port Wdward coast.He then left for Swakopmund to start a bussiness.I am visiting Swakop later on this year and would love to meet up with him again.If anyone has info please send me a mail.
Thank you
Trevor Henn.
0 Kudos
Reply