- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Modern Free-Form Fortran Version (funny_parameters.f90)
Output When You Compile and Run:
🧪 How to Compile and Run:
or using gfortran:

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page