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

Fun with fixed-form source and parameter

Harald1
New Contributor II
317 Views

Hello,

the following code in fixed-form source surprised me:

      program funny
      call foo0 ()
      call foo1 ()
      call foo2 ()
      end

      subroutine foo0 ()
      parameter (s = 42)
*     s = 42                    ! Check if PARAMETER was seen
      print *, s
      end

      subroutine foo1 ()
      parameters = 42.
*     s = 42                    ! Check if PARAMETER was seen
      print *, s
      end

      subroutine foo2 ()
      parameters = 42           ! this is somehow different...
*     s = 42                    ! Check if PARAMETER was seen
      print *, s
      end

 I get:

% ifx ifort-funny-parameter.f -what && ./a.out 
 Intel(R) Fortran 24.0-1472.3
   42.00000    
   42.00000    
          42

 I was wondering why the last print actually thinks that s is an integer and not a real.

Of course the code is not standard-conforming (diagnosed with -stand), although "legacy-style", given that the parameter statements are accepted without major complaint.

Is there something I should know about parameter in fixed-form?  Is the type of the variable s really derived from the r.h.s.?

 

0 Kudos
1 Solution
mecej4
Honored Contributor III
286 Views

The Intel Fortran documentation says:

Omission of the parentheses in a PARAMETER statement is an extension controlled by compiler option altparam. In this form, the type of the name is taken from the form of the constant rather than from implicit or explicit typing of the name.

Thus, when the non-standard interpretation is allowed/sought, the type of the variable is integer when the constant has no decimal point.

Lines 14 and 20 could be parsed as setting the  variable parameters (implicitly declared as type real) to 42.

Change those lines to

 

      parameterx = 42

 

and see the effect.

View solution in original post

4 Replies
mecej4
Honored Contributor III
287 Views

The Intel Fortran documentation says:

Omission of the parentheses in a PARAMETER statement is an extension controlled by compiler option altparam. In this form, the type of the name is taken from the form of the constant rather than from implicit or explicit typing of the name.

Thus, when the non-standard interpretation is allowed/sought, the type of the variable is integer when the constant has no decimal point.

Lines 14 and 20 could be parsed as setting the  variable parameters (implicitly declared as type real) to 42.

Change those lines to

 

      parameterx = 42

 

and see the effect.

Harald1
New Contributor II
192 Views

Hmm, I just tried my example above with -altparam and with -noaltparam and I do *not* see any difference!  Any type on the r.h.s. (integer, even complex) is used to infer the lhs type.

Maybe these options are no longer fully functional...

 

0 Kudos
andrew_4619
Honored Contributor II
278 Views

When you stray into the delta zone of implicit typing fixed form and worst of all no standards checking all manner of strange and puzzling things start to happen. In my world if you can't apply a standards then it is broken code.

Steve_Lionel
Honored Contributor III
215 Views

A bit of history: the form of PARAMETER without the parentheses was in the FORTRAN 77 draft, and DEC implemented it in several of their compilers. Then the final standard came out and the syntax (and semantics) had changed, so DEC had to support both.  This is why DEC (and other vendors) became reluctant to implement features found in draft standards.

Reply