gfortran question about optional subroutine arguments
Tim Prince
n8tm@aol.com
Thu Mar 14 17:07:00 GMT 2013
On 3/14/2013 10:40 AM, Tobias Burnus wrote:
> Mark Hounschell wrote:
>> When I use -std=f95 this fortran77 code will not compile.
>
> Well, then the code is not a valid Fortran 77 code* but uses some
> vendor extension; using vendor extensions is very common with old
> so-called "Fortran 77" code. (* valid = valid according to the Fortran
> 77 standard, cf. http://gcc.gnu.org/wiki/GFortranStandards ) Using
> -std=gnu and -std=legacy, gfortran enables support for some more or
> less common vendor extensions.
>
> What I meant before is that using -std=gnu (the default) doesn't
> disable the support for features which are in -std=f2003. Similarly
> for -std=legacy, which should also add only new features without
> disabling others.
>
>> Using the default "gnu" mostly just lots of warnings show up. Is
>> "if(present(arg2)) arg2 = 0" available when using gnu?
>
> Yes, it is definitely available with both -std=gnu and -std=legacy.
> However, it requires you declare the dummy argument as OPTIONAL.
>
>> Maybe my warnings can be suppressed with other switches.
>
> Well, using -std=gnu or -std=legacy to silence those warnings is fine;
> as written, they essentially just allow more features, which should
> usually not break things.
>
>>> Hmm, I have not seen the ",)" syntax before. I assume that that is some
>>> vendor extension, where the compiler does something - or a typo and it
>>> should be "arg1)" without ",".
>>>
>>
>> No, the "," is how this old compiler knows I'm not passing that arg.
>> The same could be done as
>> call (arg1,,arg3)
>>
>> Indicating arg2 was not passed. Also, the very last arg can always be
>> left out without using the ",".
>
> Seems as if this is a vendor extension, which only few compilers
> support. I just tried the compilers of PGI, PathScale, NAG, SUN, Cray,
> and Intel - and only Intel's ifort seems to support this extension.
>
> And, doing some digging, I also found out that GCC's g77 supports this
> feature:
> http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Ugly-Null-Arguments.html
> (g77 is the predecessor of gfortran. gfortran was written from scratch
> to support Fortran 90+. It has most but not not all legacy features of
> g77. [On the other hand, it has some vendor extensions which g77 does
> not have.])
>
> Thus, one option would be to use GCC 3.4.6's g77. However, GCC 3.x and
> g77 are no longer supported and g77 also only supports very few
> Fortran 90 features. Thus, I think it would be best to change the code
> to be fully Fortran conform.
>
> Actually, I wonder how ifort and g77 pass those 'null arguments'; or
> rather, how to use then in the called procedure. Something PRESENT()
> does not seem to exist. g77's documentation does not tell this (but
> one can look at the source code) and Intel's documentation does not
> mention this feature.
>
> Regarding gfortran: In principle, one could add support for null
> arguments; however, given that they seem to be only in few old codes,
> I don't think that this has a high priority.
>
>
> Tobias
I do recall following the g77/gcc documentation on optional arguments
when implementing date_and_time, so you might check libg2c source code
as well as continuing documentation search, if you're sufficiently
interested. I don't think anyone considered it as more than a stop-gap
while waiting for the nearly miraculous advent of gfortran. You had to
be very careful about the subset usages of date_and_time for VMS Fortran
and g77 which we used for y2k qualification, although the compiler would
normally tell you if you over-stepped the limits.
--
Tim Prince
More information about the Gcc-help
mailing list