A portable way to suppress an "unused dummy argument" warning in Fortran -
is there portable way suppress "unused dummy argument" warning in fortran specific variable similar (void)var;
trick in c/c++?
a motivational example (by request vladimir f). strategy pattern, gof example different line-breaking strategies, unnecessary details omitted.
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) :: 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) :: print *, "composing using simple compositor." end subroutine linebreaking_simple_compositor_compose subroutine linebreaking_tex_compositor_compose(this) class(linebreaking_tex_compositor), intent(in) :: print *, "composing using tex compositor." end subroutine linebreaking_tex_compositor_compose subroutine linebreaking_array_compositor_compose(this) class(linebreaking_array_compositor), intent(in) :: print *, "composing using array compositor interval", this%interval, "." end subroutine linebreaking_array_compositor_compose end module linebreaking
as can see passed-object dummy argument this
required in compose
method of linebreaking_array_compositor
, not used in same method of 2 other compositors. gfortran complains this
not being used, , don't want complicate build process having specific rules (like -wno-unused-dummy-argument
) specific files.
i have no entirely satisfactory solution problem.
care needs take whatever simple source construct gets used doesn't inadvertently turn conforming code unused dummy argument non-conforming code. experience has been easy wrong, careful cost of cure not exceed cost of disease. more not these days, ignore warning in compiler's output.
(from perspective, use of preprocessor comes cost far greater of actual warning - in code no longer standard conforming.)
for non-pointer, non-allocatable, non-optional, intent(in)-like dummy arguments of numeric intrinsic type know defined use pattern such if (arg /= 0) continue
. eliminate comparison logical, use len(arg) /= 0
character.
for non-pointer, non-allocatable, non-optional, intent(in) dummy arguments of derived type, conditional expression has specific derived type - perhaps there convenient non-allocatable, non-pointer component of intrinsic type can tested. in cases have explicitly added such component derived type might otherwise empty.
for optional dummy arguments, test presence of argument. pointer dummy arguments known have defined association status, test association status. allocatable arguments, test allocation status.
in cases above use of continue action statement if statement easy enough identify in source reader or sort of text search pattern. when compiling optimisation enabled, reasonable optimising compiler eliminate otherwise pointless test.
failure define intent(out)-like argument plausibly suggests programming error, if not, , actual argument known definable (!) - define argument, perhaps dummy value. similarly, situation definition status of argument (or pointer association status of pointer argument) may undefined suggests latent coding/code design issue - define relevant actual argument (perhaps dummy value) prior call.
Comments
Post a Comment