gfortran question about optional subroutine arguments

Mark Hounschell markh@compro.net
Mon Mar 18 13:10:00 GMT 2013


On 03/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.
>
>

Thanks for the info Tobias. I was able to make progress using -std=gnu. 
However I ran into other problems because this code also uses "optional" 
alternate returns.  So while I was able to use present() successfully, I 
can no longer use "optional" alternate returns. I read in the doc that 
for f90 > that is the case. So I was wondering, is there a way, like a 
switch or something, to make those "optional" args that are not passed 
in, just end up as NULL pointers when not passed in?

Thanks and regards
Mark



More information about the Gcc-help mailing list