Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29435 ディスカッション

Optional Argument Problem

Bruce_Ikelheimer
ビギナー
1,203件の閲覧回数

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 件の賞賛
6 返答(返信)
bmchenry
新規コントリビューター II
1,203件の閲覧回数

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?

Bruce_Ikelheimer
ビギナー
1,203件の閲覧回数

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.

Steven_L_Intel1
従業員
1,203件の閲覧回数

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.

Bruce_Ikelheimer
ビギナー
1,203件の閲覧回数

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

Bruce_Ikelheimer
ビギナー
1,203件の閲覧回数

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.

Steven_L_Intel1
従業員
1,203件の閲覧回数

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!

返信