- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
here the basics of allocated characters are discussed:
https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/287349
Now I have the following minimal working example:
! program character_array_allocation implicit none ! Variables character(len=:),dimension(:), allocatable :: foo allocate(character(len=10),dimension(20) :: foo) ! this fails ! 1>------ Build started: Project: character_array_allocation, Configuration: Debug Win32 ------ ! 1>Compiling with Intel(R) Visual Fortran Compiler 17.0.1.143 [IA-32]... ! 1>character_array_allocation.f90 ! 1>... \character_array_allocation.f90(7): error #5082: Syntax error, found ',' when expecting one of: . , [ % . ( :: ) ! 1>compilation aborted for ... \character_array_allocation.f90 (code 1) !allocate(character(len=10) :: foo(20)) ! this works end program character_array_allocation
Why causes the alternative format in line 7 a compiler error? The version in line 15 works fine.
Thanks, Johannes
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do not think the syntax that is failing is valid Fortran. At the very least I do not remember seeing that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Arjen,
thanks for your answer. My thought was, if the definition in line 5 is valid, why should it not be valid in the allocation. Sounded logically for me, but maybe isn't. gfortran (4.8.x) does not accept line 7 also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that might have been logical, indeed. I do not know why it should not be, but the type clause "character(len=10):" is a later addition to the allocate statement. (It is necessary because of polymorphic variables. And its use for specifying the length is a bonus.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I also think your syntax is invalid.
As a side note I find the "dimension" attribute a bit too verbose and rather unnecessary in the language. In my mind it is a throw back to ancient history. The only benefit I can think of is where you have a long list of variables that all have the same dimensions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks all,
the dimension attribute seems not to be allowed at all in an allocation statement. It does not work for real kinds, too. I agree, that this seems to be wrong syntax and the compiler correctly gives an error.
The dimension attribute is used widely in text books and I personally like it, because it make the code better readable IMHO. But that's a personal preference...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
DIMENSION is for declarations - it's fine there, though is generally considered old-fashioned. It's not for ALLOCATE.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
thanks for clarification. Would you suggest not to use 'DIMENSION' anymore as an attribute or is this just a matter of style?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's just style. My own style is that I may use DIMENSION(:) with POINTER or ALLOCATABLE, but not with fixed dimensions. I'm not consistent about this, though.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page