missing optional params..

Christopher D. Rickett crickett@lanl.gov
Wed Aug 16 15:11:00 GMT 2006


thanks for the help.  i thought NULL was the correct answer.  this did
cause a problem with my code for c_associated, which has an optional
second param.  both params are of type c_ptr.  if the second c_ptr is not
given it looks the same as if it was given and had a value of NULL to
begin with.  this causes a small problem since i have to distinguish
between not-present and NULL.

in this case it was simple enough to get around the problem during the
resolution of the function, but i thought that i would point it out.

Chris

> Christopher,
>
> Yes, you are right.  Look at this:
>
> [prt@localhost prs]# cat test.f90
>   real :: z = 1.0
>   call foo ()
>   call foo (z)
> contains
>   subroutine foo (x)
>     real, optional :: x
>     if (present(x)) x = 2.0 * x
>   end subroutine foo
> [prt@localhost prs]# /svn-4.2/bin/gfortran -fdump-tree-original
> test.f90f90
> [prt@localhost prs]# cat test*nal
> foo (x)
> {
>   if (x != 0B)
>     {
>       *x = *x * 2.0e+0;
>     }
>   else
>     {
>       (void) 0;
>     }
>
>
> MAIN__ ()
> {
>   static real4 z = 1.0e+0;
>   static void foo (real4 *);
>
>   _gfortran_set_std (70, 127, 0);
>   foo (0B);
>   foo (&z);
> }
>
> Best regards
>
> Paul
>



More information about the Fortran mailing list