#author("2024-09-20T17:05:38+09:00","default:Miyashita","Miyashita")
#author("2024-09-20T17:05:47+09:00","default:Miyashita","Miyashita")
* -fbounds-checkをつけるとcharacterの長さにも厳格になっちゃう問題[#y49e2e82]
**環境 [#g052f836]
#codeprettify{{
$ gfortran --version
GNU Fortran (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
}}
~

**エラー状況 [#h9f80473]
デバッグ時によくコンパイラオプションで -fbounds-check をつけると思うのだが,これをつけることで(なくても正常に動作するのに)エラーになってしまうケースがあった.~
エラー内容は書きの通り.~
 At line 269 of file mod_mygmt_gridio.f90
 Fortran runtime error: Actual string length is shorter than the declared one for dummy argument 'infilename' (111/256)
どうやら subrountine 内で character 型の引数を宣言してそのときに長さも確保しているので,bounds-check が入って長さが実際の引数の文字列長と違うじゃないか,ということらしい.~
#codeprettify(lang-fortran){{
  character(len=256), intent(in) :: infilename
}}
~

**対処 [#sc281346]
可変長 (len=*) にする.やることは[[サブルーチンでの文字列変数の引き渡し>../文字列の扱い#k476b357]]に書いたことと同じ.
#codeprettify(lang-fortran){{
  character(len=*), intent(in) :: infilename
}}

Front page   Edit Diff Attach Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes