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

Simpler for for type declaration

Andrew_Smith
Valued Contributor I
799 Views

Steve, why is it that the TYPE keyword was needed? The double colon alone would have made it clear we were referring to a type.

So instead of

TYPE(FOO) :: variable

We could have just had:

FOO :: variable

Does the ability to declare TYPE or CLASS dummy arguments improve performance? To me its seams unnecessary to have this complication of arguments being converted to and from polymorphic and that it would worsen performance.

0 Kudos
5 Replies
andrew_4619
Honored Contributor III
779 Views

Yes it is simpler  but I will note double colon is optional in which case it maybe become ambiguous.

0 Kudos
Steve_Lionel
Honored Contributor III
775 Views

Not every change in the standard is for performance - indeed most are there to improve programmer productivity. Sure, anything that defers decisions to runtime will reduce performance, (CLASS does this, TYPE does not), but polymorphism greatly simplifies some aspects of programming and appears in many other languages.

 

0 Kudos
JohnNichols
Valued Contributor III
722 Views

There is a long and deadly boring discussion on the difference between Fortran and FORTRAN on the Fortran discourse forum.  It echoes rather badly the excellent points made by Steve. 

If you need the program to run faster, it is usually much more cost effective to buy a better computer.  A Intel CORE i9 with bells and whistles like the Old No 9 train is merely 3200 USD.  Less than the cost of a programmer for a week.  Or you get a special Fortran computer and do not put anything else on it.  

Really you only need LISP and FORTRAN, everything else is just cake, but human beans make lots of cakes, some good and some excellent, in cake terms you need LISP and FORTRAN, the rest is just a nice sugar on the top to improve programming productivity.  

 

 

 

0 Kudos
FortranFan
Honored Contributor III
683 Views

Additionally, there are no "reserved" words in Fortran and therefore code such as the following shall be conformant:

 

      type pointer
         integer :: n = 42
      end type
      type(pointer), allocatable :: a !<-- imagine this instruction without TYPE()
      allocate( a )
      print *, a%n
end
C:\temp>gfortran -ffree-form p.f -o p.exe

C:\temp>p.exe
          42
C:\temp>ifx /free /standard-semantics p.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2023.2.0 Build 20230627
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.36.32537.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:p.exe
-subsystem:console
p.obj

C:\temp>p.exe
 42

 

Now, imagine the instruction on line 4 without `TYPE(..)` enclosure.

0 Kudos
Steve_Lionel
Honored Contributor III
675 Views

@FortranFan wrote:

Additionally, there are no "reserved" words in Fortran

Quite true (I wrote about that here), but you can't declare your own derived type that has the same name as an intrinsic type, and you are allowed to name intrinsic types in a type() declaration.

C734 (R727) A derived type type-name shall not be DOUBLEPRECISION or the same as the name of any intrinsic type defined in this document.

R703 declaration-type-spec is intrinsic-type-spec
 or TYPE ( intrinsic-type-spec )
 or TYPE ( derived-type-spec )
 or TYPE ( enum-type-spec )
 or TYPE ( enumeration-type-spec )

0 Kudos
Reply