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

Fix warning

ferrad01
Beginner
1,459 Views
Any idea how I can fix this warning?

props.for(1): warning #7984: A CHARACTER function name must not be declared with an asterisk type-param-value (i.e., (LEN=*)) if the function is part of an interface-body. No interface block will be generated. [PROPNAME]


props.for:
CHARACTER(LEN=*) function PropName (index)
USE PROPS
IMPLICIT NONE
integer index
PropName = PropNames(index)
return
end


I complie with:
/nologo /debug:full /Od /I"..\\asap" /DWIN32 /DDEBUG /free /d_lines /fpscomp:ioformat /warn:interfaces /assume:dummy_aliases /assume:byterecl /Qzero /fpe:0 /fp:source /names:uppercase /iface:cvf /module:"..\\..\\mod\\Debug\\\\" /object:"..\\..\\tmp\\Debug\\estm\\estm\\\\" /traceback /check:all /libs:static /threads /dbglibs /c
0 Kudos
6 Replies
Arjen_Markus
Honored Contributor II
1,459 Views
Do not use CHARACTER(LEN=*) functions!

They are defined by the standard, but they are very awkward to handle properly.

If you need to have a variable length character string as the result, try something
along these lines:

function doubleString(string)
character(len=*) ::string
character(len=2*len(string) :: doubleString

doubleString = string // string
end function doubleString

You will need to specify the string length for the result using such a specification expression.

(I won't try to explain now what character(len=*) functions are about, but they are likely
different than what you want)

Regards,

Arjen
0 Kudos
ferrad01
Beginner
1,459 Views
Thanks.

But why is my code any different from specifying a variable length string as an argument? In both cases the caller sets the string length.

Adrian
0 Kudos
Arjen_Markus
Honored Contributor II
1,459 Views

If you have a dummy characterargument, the length to be used inside the routine comes from
outside it, from the caller. How would the routine however be able to reserve the space for the
result if you do not specify the length? (That is actually what character(len=*) function does -
it allows the _caller_ to specify the length of the result)

You could use an allocatable-length string:

function doubleString( string )
character(len=*) :: string
character(len=:), allocatable :: doubleString

allocate( character(len=2*len(string) :: doubleString )

doubleString = string//string
end function doubleString

Now you can do whatever computations you need in your actual case
to allocate a string of suitable length and fill it.

Regards,

Arjen

0 Kudos
Steven_L_Intel1
Employee
1,459 Views
The problem here really is that the default is for generated interface checking in a Debug configuration but the generated interface does not support the deleted (from the current Fortran standrd) feature of a CHARACTER(*) function. The compiler supports the feature but not in an interface block (since the standard doesn't).

I agree with those who recommend against using CHARACTER(*) functions as they don't do what most people think they do. You can now have character functions that have lengths dependent on the lengths of dummy arguments or even a deferred-length allocatable result.
0 Kudos
ferrad01
Beginner
1,459 Views
But the caller sets the string length in both cases (as an argument and also for the function)

ie. if I have
character(len=*) function ch1(ch2)
character(len=*) :: ch2
ch1 = trim(ch2)//' the wind'
return
end


then I could call with

character(len=64) :: ch1
write(6,'(a)') ch1('gone with')

which I tested and works.

I'm not sure what the issue is with this. In your code restructuring example, what happens if I don't know what length to declare doubleString to?

Adrian
0 Kudos
Arjen_Markus
Honored Contributor II
1,459 Views
Using my example you can use the function as follows:

character(len=:), allocatable:: result
result = doubleString( "A string to be doubled" ) ! Assumes automatic reallocation will take place

write(*,*) doubleString( "A string to be doubled" ) ! The result string is not stored, so no worries

call doSomethingElse( doubleString( "A string to be doubled" ) ) ! The string is passed to a subroutine that
! knows exactly what length it has

The same length problem occurs with a character(len=*) function of course.

Regards,

Arjen
0 Kudos
Reply