implied do loop の局所スコープの bug
program F2018 implicit none integer, allocatable :: m(:) m = [(i, integer:: i = 1, 10)] print *, m end program F2018
この単純な形でコンパイル時の syntax error が出る。
loop.f90(5): error #6404: This name does not have a type, and must have an explicit type. [I]
しかし、implicit none を外したり integer :: i の宣言を入れるとコンパイル通る。
program F2018 ! implicit none integer, allocatable :: m(:) m = [(i, integer:: i = 1, 10)] print *, m end program F2018
1 2 3 4 5 6 7 8 9 10
forall の時も同じことをやっているので Intel 進歩してない。多分チェックプログラムに implicit none を付けてないw implicit none の場合は integer(8) にすると変数 i はちゃんと 8 byte になるが、implicit none ; integer :: i で 4byte 変数として宣言してあると、implied do loop 中で 8byte 宣言しても 4byte 変数となって overflow するキチガイ挙動w
program F2018 ! implicit none integer(8), allocatable :: m(:) m = [(i, integer(8):: i = 10_8**10, 10_8**10 + 10)] print *, m end program F2018
10000000000 10000000001 10000000002 10000000003 10000000004 10000000005 10000000006 10000000007 10000000008 10000000009 10000000010
program F2018 ! implicit none integer :: i integer(8), allocatable :: m(:) m = [(i, integer(8):: i = 10_8**10, 10_8**10 + 10)] print *, m end program F2018
1410065408 1410065409 1410065410 1410065411 1410065412 1410065413 1410065414 1410065415 1410065416 1410065417 1410065418

Modern Fortran: Building efficient parallel applications
- 作者:Curcic, Milan
- 発売日: 2020/11/24
- メディア: ペーパーバック
大室家4巻
大室家4巻 特装版の付録はみさきち話で私的にイマイチ。小学生世代では、こころちゃんが好き。
なお公式略語も OMRK と先頭の母音以外は母音を抜いて子音を並べる FORTRAN の変数名づけのようで好ましい。

- 作者:なもり
- 発売日: 2020/12/23
- メディア: コミック
先生たちの方は、まだこれからか・・・
補足
Fortran 2018 とは関係なくて Fortran 2003 水準での話ですが、implied do loop そのままだと loop 変数の値が残るのに、これを配列構成子の中に置くと、loop 変数の終了値が残らないという不思議。gfortran でもそうなっているので規格上の挙動なのでしょうか・・・?規格を調べる気力が起きないです。
(配列構成子を (/.../) にすれば Fortran90 水準の話の気もします。そのうち調べたいです。)
program Hello i = 99 print *, i print *, (i, i = 1, 10) print *, i i = 99 print *, i print *, [(i, i = 1, 10)] print *, i end program Hello
一個目は loop を抜けた後で i=11 になっているのに、二個目は loop を抜けても loop に入る前の値の i=99 を保っている。
$main 99 1 2 3 4 5 6 7 8 9 10 11 99 1 2 3 4 5 6 7 8 9 10 99