- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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
endI get:
% ifx ifort-funny-parameter.f -what && ./a.out
Intel(R) Fortran 24.0-1472.3
42.00000
42.00000
42I 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.?
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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 kopiert
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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...
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Modern Free-Form Fortran Version (funny_parameters.f90)
Output When You Compile and Run:
🧪 How to Compile and Run:
or using gfortran:
- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite