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

with - end with code block?

Averkov__Igor
Beginner
488 Views
Hello!
Many another languages support a very helpful feature: with end with block
Can it one day be realized in Fortran?

Example:
[fortran]type TStruct
  real Value1
  real Value2
  real Value3
end type

type(TStruct) Struct

! long notation
Struct%Value3 = Struct%Value1 + Struct%Value2 ! much better: with Struct Value3 = Value1 + Value2 end with[/fortran]

0 Kudos
2 Replies
Arjen_Markus
Honored Contributor II
488 Views

The associate cosntruction is what you are after, but it is more general than just such a "with" construction.
It was introduced in Fortran 2003.

The example could become:

associate( s => struct )
s%value3 = s%value1 + s%value2
end associate

but it gets its power from:

associate( s1 => struct, s2 => someOtherStruct, s3 => aThirdOne )
...
end associate

Regards,

Arjen

0 Kudos
Averkov__Igor
Beginner
488 Views
thank you very much for answer. I was not able to reply for a long time.
0 Kudos
Reply