Re: double confusion



On 2006-07-17 15:38:52 -0300, glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx> said:

Gordon Sande wrote:

(snip)

You could try to use an "IMPLICIT NONE" and see what happens.

Doesn't IMPLICIT have the same scoping problem as other declarations?

The OP thought that a declaration of the following function would
be used by the preceding program because they were in the same file.
If there had been an IMPLICIT NONE in the main there would have been
diagnostics about the missing declaration of the function.

The IMPLICIT NONE would have made it rather explicit that there was
no declaration of the double precision function in the scope of the
main program. The problem was to purge the scope of default declarations
so the OP would know what declarations the compiler was applying. The
problem was the implicit defaults and the F77 linking rules allowing
a program into execution where it did not work correctly.

The OP had the "look and feel" of someone who expected the C rules
on file scope to apply to Fortran separate compilations. So the
question was how to make it easily explicit that something was
missing. Undoubtedly some poor overworked soldier who had been told
"You're a programmer. Deal with this."

When you rely on defaults one of the problems is that you have
to know what the defaults actually are. In Fortran the default types
are integer and real according to the initial letter.

Fortran has no notion of file scope so the beginning is actually the
beginning of the main program. It would be much clearer if you had used
a PRGOGRAM statement. Then you would have gotten an obscure diagnostic
about two main programs which would have indicated that something was
not quite as you had guessed it to be.

-- glen


.



Relevant Pages

  • Re: double confusion
    ... If there had been an IMPLICIT NONE in the main there would have been ... of the main program as somehow the assumption was that declarations ... Sometimes it helps to point out that separate compilation can be ... As we know, Fortran doesn't do that. ...
    (comp.lang.fortran)
  • Re: double precision g77
    ... so changed all REAL declarations to DOUBLE PRECISION and changed FUNCTION ... If you don't use implicit none, then changing all the REAL declarations ... Changing declarations does nothing about literal ...
    (comp.lang.fortran)
  • Re: Module Fortran 90
    ... implicit none ... integer,dimension, pointer:: A ... is not declarations that are accessed from a module. ... compiler), showing exactly what you did, and exactly what the resulting ...
    (comp.lang.fortran)
  • Re: double precision g77
    ... so changed all REAL declarations to DOUBLE PRECISION and changed FUNCTION ... If you don't use implicit none, then changing all the REAL declarations ... double precision function foo() ...
    (comp.lang.fortran)
  • Re: CLASS Terminology
    ... Fortran uses several names that have completely ... Item 5 above is a bit inconsistent in that it does not apply to type declarations with the CLASS keyword and is ... I think it has been suggested that the next standard beyond Fortran ...
    (comp.lang.fortran)