C/C++の(void)var;
と同様の特定の変数に対してFortranで "未使用の仮引数"警告を抑制する移植可能な方法はありますか?Fortranで "未使用の仮引数"警告を抑制する移植可能な方法
(Vladimir Fからの要求による)動機付けの例。ストラテジパターン、GoFの例、さまざまな改行方法、不要な詳細は省略されています。
module linebreaking
type, abstract :: linebreaking_compositor
contains
procedure(linebreaking_compositor_compose), deferred, pass(this) :: compose
end type
abstract interface
subroutine linebreaking_compositor_compose(this)
import linebreaking_compositor
class(linebreaking_compositor), intent(in) :: this
end subroutine linebreaking_compositor_compose
end interface
type, extends(linebreaking_compositor) :: linebreaking_simple_compositor
contains
procedure, pass(this) :: compose => linebreaking_simple_compositor_compose
end type linebreaking_simple_compositor
type, extends(linebreaking_compositor) :: linebreaking_tex_compositor
contains
procedure, pass(this) :: compose => linebreaking_tex_compositor_compose
end type linebreaking_tex_compositor
type, extends(linebreaking_compositor) :: linebreaking_array_compositor
private
integer :: interval
contains
procedure, pass(this) :: compose => linebreaking_array_compositor_compose
end type linebreaking_array_compositor
contains
subroutine linebreaking_simple_compositor_compose(this)
class(linebreaking_simple_compositor), intent(in) :: this
print *, "Composing using a simple compositor."
end subroutine linebreaking_simple_compositor_compose
subroutine linebreaking_tex_compositor_compose(this)
class(linebreaking_tex_compositor), intent(in) :: this
print *, "Composing using a TeX compositor."
end subroutine linebreaking_tex_compositor_compose
subroutine linebreaking_array_compositor_compose(this)
class(linebreaking_array_compositor), intent(in) :: this
print *, "Composing using an array compositor with interval", this%interval, "."
end subroutine linebreaking_array_compositor_compose
end module linebreaking
あなたが見ることができるように渡されたオブジェクトの仮引数this
はlinebreaking_array_compositor
のcompose
方法で必要とされるが、他の二つのコンポジターのと同じ方法で使用されていません。 GFortranは、this
が使用されていないと不満を持ち、特定のファイルに対して特定のルール(例えば、-Wno-unused-dummy-argument
)を設定することによってビルドプロセスを複雑にしたくありません。
あなたはあなたが何かを説明する必要があります。なぜ警告を無効にしないのですか? (GCC '-Wno-unused-dummy-argument'の中で) –
質問は、何か役に立たない警告を避けるために、完全に正しいコードを難読化して障害を起こすのはなぜですか? –
心配しないで、私は何をしているのか知っています。 :D要するに、生産コードを難読化することではない。むしろ、私は単純なOOPショーケースをたくさん持っています。その単純さのために、この引数を使用しない(単に何かを印刷する)渡されたオブジェクトの仮引数でタイプバインドされたプロシージャが時折あることがあります。私は単純に引数を取り除くことはできません。なぜなら、それが使用されないプロシージャが親タイプのプロシージャを上書きし、この引数が必要な他の派生型はほとんどないからです。 – Wildcat