On Mon, Apr 07, 2025 at 02:42:10PM +0800, Gwen Fu wrote:
> Thanks for your reply !
> >The word "parameter" has very a specific meaning in Fortran. The
> >entity that is passed into a function or subroutine is an "actual
> >argument". The entity within the functions associated with the
> >"actual argument" is a "dummy argument".
> 
> Can I understand "dummy parameters" as temporary variables in a function
> similar to C/C++, which copy the value of the passed parameter?
> Or this is pass by value in C++.

Not in Fortran terminology.

program foo
  integer, parameter :: bar = 1
  print *, bar
end program foo

'parameter' is an attribute that is used to designate a named constant.

program foo
  call bar(i)
  print *, i
end
subroutine bar(j)
  j = 42
end 

'i' is an actual argument, and it is implicitly typed.
'j' is a dummy argument, and it is implicitly typed.

Fortran standard does not prescribe pass-by-value or pass-by-reference,
except if the 'dummy argument' has a 'value' attribute.  The 'value'
attribute the interface for the subprogram must have an explicit 
interface.

> >It is not clear to me what you're trying to accomplish. gfortran
> >already has an -fimplicit-none option that enforces no implicit
> >typing. This option will catch the "typo" type error. Gfortran
> >also has the -fallow-argument-mismatch. If the code is within
> >a single file, gfortran will build an explicit interface when
> >it encounters an external procedure, and then it uses that interface
> >to check any additional references.
> I looked up the meaning of these two compilation options.
> Both of them are compile time options .
> But this project  needs to provide an option run-time test .
> I am currently trying to understand the concept of runtime options and
> what can happen.

It is still unclear to me what you are trying to accomplish.
Implicit typying and implicit interfaces are a compile-time
thing.  

function foo(x)
  foo = x * x
end

The above has an implicit interface and implicit types for
'foo' and 'x'.  The -fimplicit-none option capture this.

% gfortran14  -c a.f90
troutmask:kargl[206] gfortran14 -c -fimplicit-none a.f90
a.f90:1:14:

    1 | function foo(x)
      |              1
Error: Symbol 'x' at (1) has no IMPLICIT type
a.f90:1:0:

    1 | function foo(x)
Error: Function 'foo' at (1) has no IMPLICIT type


An -fcheck=implicit-type option that generates a runtime
error that does not make sense to me unless the aim is
to slow down the compile code.  The above code would be
transformed into something like (ignoring passing convention).

float
foo(float x)
{
  if (runtime_option & fcheck_implicit_type)
     runtime_error("'foo' has an implicit type");

  if (runtime_option & fcheck_implicit_type)
     runtime_error("'x' has an implicit type");

  return (x * x);
} 

-- 
Steve

Reply via email to