- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I've notice that depending on the compiler used, the following program fails or succeeds compilation.
The program is related to type character length allocation using deferred type parameters.
The ifort compiler successds tha compilation whereas the gfortran fails.
Here is the program:
How could I allocate a character with a non-parameter integer variable ?
I know that this can be acheived using parameterized derived types.
Can it be acheived by a simpler way ?
Thanks.
I've notice that depending on the compiler used, the following program fails or succeeds compilation.
The program is related to type character length allocation using deferred type parameters.
The ifort compiler successds tha compilation whereas the gfortran fails.
Here is the program:
[fortran]Program test integer :: N1=5 integer ,parameter:: N2=5 character(len=:), allocatable :: string1, string2 allocate(character(len=N1) :: string1) ! Problem with gfortran: "Error: Variable 'n1' cannot appear in the expression at (1)" allocate(character(len=N2) :: string2) write(6,*) len(string1) write(6,*) len(string2) End Program[/fortran]The problem encontered by gfortran is that the N1 integer variable is used in the "allocate" statement to set the length of the string but this variable (N1) is not defined with the parameter attribute.
How could I allocate a character with a non-parameter integer variable ?
I know that this can be acheived using parameterized derived types.
Can it be acheived by a simpler way ?
Thanks.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have hit a gfortran missing feature or bug - see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45170#c14. It erroneously rejects expressions that aren't specification expressions in length specifiers.
if your source must compile with both compilers then comments in the bug report give you a work-around alternative to the allocate statement such as:
string1 = repeat(' ',N1)
if your source must compile with both compilers then comments in the bug report give you a work-around alternative to the allocate statement such as:
string1 = repeat(' ',N1)

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