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

Optional Argument Problem

Bruce_Ikelheimer
Beginner
362 Views

I have been having difficulty getting an optional argument to work properly. I've got a Fortran written DLL with many passed arguments. The last two are optional...an integer and a real*8. If I do not pass along these two arguments to the DLL and examine what is received by the DLL, the integer is registered as ' Undefined pointer/array' and is correctly identified as .false. with a 'Present' command. The real, however, is registered as an 'Undefined address', and is incorrectly identified as .true. with a 'Present' command. I've tried much simpler test cases that do not use the DLL interface and they work fine. Is there something going wacky with the DLL? Everything is written in Fortran, so I'd think that the interface would be fairly simple...

0 Kudos
6 Replies
bmchenry
New Contributor II
362 Views

ummm....if they are optional and you do not pass them to the routine then in the routine they are undefined. which you are finding properly. Any additional tests on them would be if, and only if, they are defined. Since 'undefined' means who knows or cares what's in those placeholders?

0 Kudos
Bruce_Ikelheimer
Beginner
362 Views

The placeholders, as identified when I pause the program to debug are different.  The integer is 'Undefined pointer/array' while the real is 'Unidentified'.  Apparently this difference matters to the compiler because it still thinks something was passed into the 'Unidentified' variable (even though nothing was).  Very frustrating.

0 Kudos
Steven_L_Intel1
Employee
362 Views

If you have OPTIONAL arguments, an explicit interface to the procedure must be visible to the caller. Did you do this?

See also Doctor Fortran and the Virtues of Omission.

0 Kudos
Bruce_Ikelheimer
Beginner
362 Views

Steve - I had not done that (hand smack upside the head).  I'll give that a try and keep you posted.  Thanks!

0 Kudos
Bruce_Ikelheimer
Beginner
362 Views

Steve - Thanks, as always!  I did not know that the otional arguments needed the interface, but it makes perfect sense.  I've added the interface and everything works great.

0 Kudos
Steven_L_Intel1
Employee
362 Views

Normally, when the caller and callee are compiled in the same project, the default "Generated Interface Checking" feature would catch this, but if you had your DLL as a separate project and, obviously, didn't have a module defining the interface, you'd run into this problem.

I'll also recommend a read of Doctor Fortran Gets Explicit - Again!

0 Kudos
Reply