Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29001 Discussions

character combination in Intel visual fortran fails

forni
Beginner
292 Views

CHARACTER*100 RIGA,FMT,KEY


KEY='123'
RIGA=''

IT FAILS WITH THE FOLLOWING ERROR:


KEY='123'
RIGA=''

IT FAILS WITH THE FOLLOWING ERROR:


KEY='123'
RIGA=''

IT FAILS WITH THE FOLLOWING ERROR:

DUMMY CHARACTER KEY HAS LENGTH 100 WICH IS GREATHER THAN ACTUAL VARIABLE LENGTH 3

SAME PROBLEM IF I USE INTERNAL WRITE WITH PROPER FORMAT

THIS WORKED FINE IN COMPAQ VISUAL FORTRAN

ANY IDEA HOW TO MANAGE WITH DINAMIC LENGTH CHARACTER VARIABLES WITH INTEL VISUAL FORTRAN?

0 Kudos
2 Replies
mecej4
Honored Contributor III
292 Views
The pieces of code that you showed do not show that KEY is a dummy argument, and we do not know what the actual argument is other than what the compiler error message indicates.

If you subroutine uses only KEY(1:3), why not declare KEY as character(3), or, even better, CHARACTER(*) ?

On the other hand, if in other places in the subroutine (which you did not show) you access KEY as if it was longer than the actual argument, the code is illegal and should be fixed, even if by a fluke it used to give expected results with another compiler.

The variable KEY has the length that it had at the point of calling, if it is not ALLOCATABLE or has the POINTER attribute. It is not a dynamic string. Perhaps this fact makes it easier to understand why it should not be treated as an indefinitely extensible string.
0 Kudos
Steven_L_Intel1
Employee
292 Views
If RIGA is a dummy argument it should be declared CHARACTER(*). The error message you describe will occur if you have declared a dummy argument of an explicit length but pass an actual argument which is shorter than that length. This is not legal Fortran and can lead to unexpected results.

In general you should always use CHARACTER(*) for dummy arguments unless you have a good reason not to do so.
0 Kudos
Reply