- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Hi,
1- I am trying to define a string with dynamic length at the beginning of a subroutine as the line declared here:
here is my decleration:
character(len=:), allocatable::stringBuff(:)
But I am getting this error:
SysCallTest.f90(314): error #5082: Syntax error, found ':' when expecting one of: ( * ...
character(len=:), allocatable::stringBuff(:)
----------------^
I even tried to use this syntax:
character*(*)::stringBuff1
But again I got a similar error.
SysCallTest.f90(315): error #6832: This passed length character name has been used in an invalid context. [STRINGBUFF1]
character*(*)::stringBuff1
-----------------^
May I ask why it doesn't accept my definition?
2- In C++ we compare two strings using other functions like strcmp. Is the operator = overloaded for strings (char arrays) in fortran or I have to rely on another way of comparing?
I am using Fortran 11.0.....
Thanks for your help,
Hamidreza,
링크가 복사됨
4 응답
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Context matters. It is not possible to help when you show only a single-line declaration. The following trivial program can be compiled without error messages (with the 12.x compilers):
[fortran]character(len=:), allocatable::stringBuff(:) end [/fortran]
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Please try to compile this simple code using ifort:
Here is the error I got:
[fortran]subroutine testSub(expectedPhrase) character*(*), intent(in)::expectedPhrase character(len=:), allocatable::stringBuff(:) stringBuff = expectedPhrase end subroutine testSub[/fortran]
SysCallTest_01.f90(3): error #5082: Syntax error, found ':' when expecting one of: ( * ...
character(len=:), allocatable::stringBuff(:)
----------------^
SysCallTest_01.f90(3): error #6832: This passed length character name has been used in an invalid context. [STRINGBUFF]
character(len=:), allocatable::stringBuff(:)
---------------------------------^
compilation aborted for SysCallTest_01.f90 (code 1)
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I just noticed that you are using the 11.0 compiler. It probably does not support parameterized derived types -- a Fortran 2003 feature, an instance of which is used by the present program.
Either use a more recent issue of the compiler or do not use parameterized derived types.
Either use a more recent issue of the compiler or do not use parameterized derived types.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
This is not really parameterized derived types - it is deferred-length character allocatable. This is supported in 11.1 but not earlier.
