- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I came accross a problem with variable length strings. It you assign an unallocated string to another string you get an error.
So I thought what use is it really having an unallocated state for them when an allocated state of zero length would probably take up the same memory and be more robust. But I guess some like having the unitialized state as a debugging aid.
In my app not all instances get initialized on purpose. So I tried to provide a default initializer just like you can with a non-allocatable data types. But this turned out to be illegal. Why was this restriction for allocatables not dropped for allocatable character strings ?
How about a new string type that totally hides all the allocation stuff.
So I thought what use is it really having an unallocated state for them when an allocated state of zero length would probably take up the same memory and be more robust. But I guess some like having the unitialized state as a debugging aid.
In my app not all instances get initialized on purpose. So I tried to provide a default initializer just like you can with a non-allocatable data types. But this turned out to be illegal. Why was this restriction for allocatables not dropped for allocatable character strings ?
[bash]type Animal
character(:), allocatable :: name = ''
end type[/bash]
How about a new string type that totally hides all the allocation stuff.
[bash]type Animal
string :: name = ''
end type[/bash]
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Let us consider the corresponding situation with integers:
Remember that initialization of an allocatable component in a derived type definition is not permitted by the standard.
[fortran]module allbmod type Amphib integer, allocatable :: frog(:)=(/ 1, 2 /) end type end module allbmod[/fortran]How would you want the compiler to treat this code?
Remember that initialization of an allocatable component in a derived type definition is not permitted by the standard.

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