次の例は、dbx で割り当て済み配列を処理する方法を示しています。
demo% f95 -g Alloc.f95
demo% dbx a.out
(dbx) list 1,99
1 PROGRAM TestAllocate
2 INTEGER n, status
3 INTEGER, ALLOCATABLE :: buffer(:)
4 PRINT *, 'Size?'
5 READ *, n
6 ALLOCATE( buffer(n), STAT=status )
7 IF ( status /= 0 ) STOP 'cannot allocate buffer'
8 buffer(n) = n
9 PRINT *, buffer(n)
10 DEALLOCATE( buffer, STAT=status)
11 END
(dbx) stop at 6
(2) stop at "alloc.f95":6
(dbx) stop at 9
(3) stop at "alloc.f95":9
(dbx) run
実行中: a.out
(プロセス id 10749)
Size?
1000
行番号 6 ではサイズは未知
MAIN で停止しました 行番号 6 ファイル"alloc.f95"
6 ALLOCATE( buffer(n), STAT=status )
(dbx) whatis buffer
integer*4 , allocatable::buffer(:)
(dbx) next
続き
MAIN で停止しました 行番号 7 ファイル "alloc.f95"
7 IF ( status /= 0 ) STOP 'cannot allocate buffer'
(dbx) whatis buffer
integer*4 buffer(1:1000)
行番号 9 ではサイズは既知
(dbx) cont
MAIN で停止しました 行番号 9 ファイル "alloc.f95"
9 PRINT *, buffer(n)
(dbx) print n
バッファー (1000) に 1000 を格納
n = 1000
(dbx) print buffer(n)
buffer(n) = 1000
|