0

I'm not sure why the compiler is complaining that "procedure attribute conflicts with intent attribute" since I specify the intent for all of the arguments. This seems like almost every other routine that I write.. Here's the first module:

  module char_mod
  implicit none
  private
  public :: char,init
  interface init;      module procedure init_char;        end interface
  interface init;      module procedure init_copy;        end interface
  type char
    character(len=1) :: c
  end type
  contains
  subroutine init_char(CH,c)
    implicit none
    type(char),intent(inout) :: CH
    character(len=1),intent(in) :: c
    CH%c = c
  end subroutine
  subroutine init_copy(a,b)
    implicit none
    type(char),intent(inout) :: a
    type(char),intent(in) :: b
    a%c = b%c
  end subroutine
  end module

Which compiles fine. But I also have a second module that builds on this:

  module varStr_mod
  use char_mod
  implicit none
  private
  public :: varStr,init
  interface init;      module procedure init_size;        end interface
  interface init;      module procedure init_string;      end interface
  type varStr
    type(char),dimension(:),allocatable :: s ! string
    integer :: n                             ! string length
  end type
  contains
  subroutine init_size(VS,n)
    implicit none
    type(varStr),intent(inout) :: VS
    integer,intent(in) :: n
    if (n.lt.1) stop 'Error: string must be of size > 1 in varStr.f90'
    if (allocated(VS%s)) deallocate(VS%s)
    allocate(VS%s(n))
    VS%n = n
  end subroutine
  subroutine init_string(VS,s)
    implicit none
    type(varStr),intent(inout) :: VS
    character(len=*),intent(in) :: s
    integer :: i,n
    n = len(s)
    call init(VS,n)
    do i=1,n
      call init(VS%s(i),s(i))
    enddo
  end subroutine
  end module

I'm getting a compiler error that says:

 subroutine init_string(VS,s)
                           1
 PROCEDURE attribute conflicts with INTENT attribute in 's' at (1)

Any help with this is greatly appreciated.

Charles
  • 947
  • 1
  • 15
  • 39
  • If you are trying to reference a length-1 substring of `s` you need `s(i: i)` not `s(i)`. – francescalus Apr 07 '16 at 21:56
  • 3
    Thank you, I realized this shortly after posting from seeing the answer to this question: http://stackoverflow.com/questions/13755762/access-character-at-specific-index-in-a-string-in-fortran – Charles Apr 07 '16 at 22:27
  • Even more exact duplicate http://stackoverflow.com/questions/27253081/fortran-intent-in/27253345#27253345 (the error message is the same) – Vladimir F Героям слава Apr 08 '16 at 09:07

0 Answers0