forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Implicit NONE partly ignored

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
mecej4



Joined: 31 Oct 2006
Posts: 1205

PostPosted: Sat Aug 17, 2019 10:57 pm    Post subject: Implicit NONE partly ignored Reply with quote

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.

Code:
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
Code:
[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
Code:
Error: Symbol 'error' at (1) has no IMPLICIT type
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2050
Location: Yateley, Hants, UK

PostPosted: Sun Aug 18, 2019 10:35 am    Post subject: Reply with quote

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:

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


Eddie
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1227
Location: Aerospace Valley

PostPosted: Sun Aug 18, 2019 5:51 pm    Post subject: Reply with quote

This is an ideal example of why a compiler should automatically flag with a WARNING and list ALL UNDEFINED variables (without having to run some fancy checking pogram).
And of course to list them in alphabetical order not just 'as found' order, to make the programmer's life liveable.

Maybe the standards committee in their wise and forward thinking wisdom have already thought of this and introduced as a requirement in F2015. :O)

In any case IMPLICIT NONE is not partly ignored is it ?
Whether it was there or not surely the variable 'error' would be treated as a real because it starts with 'e'. So the error message is logical, as it were.

LOGICAL's always have to be defined, as do CHARACTER variables.

It would be a big ask indeed for the compiler to be expected to scan the variable type needed in the context of the statement(s) it was used in now wouldn't it.
_________________
''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2050
Location: Yateley, Hants, UK

PostPosted: Sun Aug 18, 2019 7:31 pm    Post subject: Reply with quote

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:

Code:
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.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6078
Location: Salford, UK

PostPosted: Mon Aug 19, 2019 6:57 am    Post subject: Reply with quote

mecej4

Thank you for the feedback. I have made a note that this needs fixing.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6078
Location: Salford, UK

PostPosted: Mon Aug 19, 2019 1:33 pm    Post subject: Reply with quote

This has now been fixed for the next release of FTN95.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group