- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page