- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is not really parameterized derived types - it is deferred-length character allocatable. This is supported in 11.1 but not earlier.
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