Re: optional argument versus subroutine overloading



Michael Metcalf <michaelmetcalf@xxxxxxxxxxxxxx> wrote:

"Steve Lionel" <steve.lionel@xxxxxxxxx> wrote in message
news:1172679546.993183.171590@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
reubendb wrote:

Is function/subroutine overloading actually resolved
during compilation, or during run time, as in the case of presence
test ?

Overloading is typically resolved at compile time. I'd be astonished
if any implementation did it differently.

Surely the optional argument case too?

No. There are things with optional arguments that cannot reasonably be
handled at compile-time. There is, of course, felated stuff done at
compile time, but in the end analysis, if you have code that does, as it
sounds like the OP is asking about

if (present(some_argument)) then
...
end if

The present intrinsic and the condtional branch are going to be
evaluated at run time.

That being said, it sure shouldn't take much run time. I'd think it
would be swamped in the overhead of doing even the most trivial
subroutine call at all.

I would guess that you wouldn't be able to measure the difference
between the two approaches. It would sure hav eto be a tiny routine to
have any chance of seeing a difference.

Of course, if you do have an optional argument and such a test, I
wouldn't repeat the test in the middle of a time critical loop inside of
the subroutine. I'm picturing more a single test up at the top - not one
imbedded in a loop.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.



Relevant Pages