- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need to pass a character array to a subroutine using a pointer. If I pass a character variable (i.e. not an array) as below then everything works OK:
Code:
program Test_Project character(10), target :: strings character(10), pointer :: pstrings strings = 'string 1' pstrings => strings call test_sub(pstrings) end program Test_Project subroutine test_sub(str_in) character(len=*), intent(in) :: str_in print*, str_in end subroutine test_sub
However, if I attempt to pass a character array as follows then I get warning messages from the compiler about passing a character value toa non-character dummy argument and the code crashes when run.
Code:
program Test_Project character(10), dimension(10), target :: strings character(10), dimension(:), pointer :: pstrings strings = 'string 1' pstrings => strings call test_sub(pstrings) end program Test_Project subroutine test_sub(str_in) character(len=*), intent(in), dimension(:) :: str_in print*, str_in end subroutine test_sub
What's going on? Any help or solutions would be most greatfully recieved. Cheers, Tim
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve, thanks very much for the help. Looks like you've grown pretty tired of answering that question as you've gone to the trouble of putting the answer on a web-page!
Cheers, Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's actually an article I wrote several years ago, but this question does come up a lot!
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