Silverfrost Forums

Welcome to our forums

Implicit NONE partly ignored

17 Aug 2019 9:57 #24199

In the following program, a type declaration (LOGICAL) is missing for the only variable in the program. Despite the IMPLICIT NONE, the compiler thinks that the variable is implicitly typed as real.

program falsemsg
implicit none
!
if(.not.error)then
   print *,'No errors found'
else
   print *,'Errors in input data, aborting'
   stop
endif
end program

The compiler says

[FTN95/Win32 Ver. 8.51.0 Copyright (c) Silverfrost Ltd 1993-2019]
0004) if(.not.error)then
*** REAL(KIND=1) variables, such as ERROR, cannot be in logical expressions (with '.NOT.')
    1 ERROR  [<FALSEMSG> FTN95 v8.51.0]
*** Compilation failed

Gfortran says

Error: Symbol 'error' at (1) has no IMPLICIT type
18 Aug 2019 9:35 #24201

I'm with you here, Mecej4, all the way. How outrageous that IMPLICIT NONE should be *partly *ignored, when it should be completely ignored!

Joking apart, the critical thing for me in any compiler error message is that it highlights the line in which the error occurs. If the statements are kept short, then a programmer versed in the language should be able to see the error and correct it without further assistance.

Once again, if this behaviour was documented, then it would be a 'feature' not an 'error'.

As it is, I'm not sure that the Gfortran message is any better than the FTN95 one, which at least highlights the problem as lying in a logical expression with .NOT.

A better message would be to highlight that ERROR is not LOGICAL:

As ERROR is not typed as LOGICAL, it cannot be in a logical IF comparison with .NOT.

Eddie

18 Aug 2019 6:31 #24203

John,

I fear you missed the point. With IMPLICIT NONE nothing has a type, unless it is defined. FTN95 assumed that the variable was REAL, because of the implicit type rule, and that is not correct. In the context, it had to be LOGICAL, and only by knowing that, could FTN95 declare it to be an unacceptable type.

If you replace the IF with a different type/sort/kind (have all these got other meanings?) of comparison, as in the following:

0004) if (error .ne. 1) then
WARNING - Variable ERROR has been used without being given an initial value
WARNING - Comparing floating point quantities for inequality may give misleading results
*** ERROR must appear in a type declaration because IMPLICIT NONE has been used

Then you do get (eventually) to something relating to the fact that ERROR was never in a type declaration, but only after noting that it doesn't have an initial value and that it is used in a comparison that can give daft results.

As to whether IMPLICIT NONE should have any other side effects beyond marking it an undeclared variable is a matter for SF, and you of all people should know the answer if you request it!

Eddie

PS. I know it's a demonstrator, but using a variable name like ERROR has the potential to cause mayhem.

19 Aug 2019 5:57 #24205

mecej4

Thank you for the feedback. I have made a note that this needs fixing.

19 Aug 2019 12:33 #24206

This has now been fixed for the next release of FTN95.

Please login to reply.