Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

TYPE, BIND(C, NAME= not compiling

Norman_K_
New Contributor I
735 Views

What is wrong with the following?

module mod_dill

    use, intrinsic :: iso_c_binding, only: c_char
    implicit none; private
  
    public :: ipaddr
  
    type, bind(c, name='dill_ipaddr') :: ipaddr
        character(c_char) :: address(32)
    end type ipaddr
  
end module mod_dill

! ------ Build started: Project: test_tcp, Configuration: Debug|x64 ------
! 
! Compiling with Intel(R) Visual Fortran Compiler 19.0.5.281 [Intel(R) 64]...
! mod_dill.f90
! mod_dill.f90(8): error #5082: Syntax error, found ',' when expecting one of: )
! mod_dill.f90(8): error #5082: Syntax error, found '::' when expecting one of: , <END-OF-STATEMENT> ;
! mod_dill.f90(8): error #6274: This statement must not appear in the specification part of a module.
! mod_dill.f90(9): error #6236: A specification statement cannot appear in the executable section.
! mod_dill.f90(10): error #6274: This statement must not appear in the specification part of a module.
! mod_dill.f90(8): error #6404: This name does not have a type, and must have an explicit type.   
! mod_dill.f90(8): error #6632: Keyword arguments are invalid without an explicit interface.   [NAME]
! mod_dill.f90(8): error #6404: This name does not have a type, and must have an explicit type.   [BIND]
! mod_dill.f90(8): error #6404: This name does not have a type, and must have an explicit type.   [IPADDR]

Merry Christmas

 

N

0 Kudos
1 Solution
FortranFan
Honored Contributor II
735 Views

@Norman K.,

Merry Christmas.

As explained by Andrew, NAME= clause is not an option in a derived-type definition such as with your 'ipaddr' type.

Did you mean to have NAME= clause in a type declaration of a de facto 'global' object as shown below?

module mod_dill

    use, intrinsic :: iso_c_binding, only: c_char
    implicit none; private

    public :: ipaddr

    type, bind(C) :: ipaddr
        character(c_char) :: address(32)
    end type ipaddr

    type(ipaddr), bind(C, name='dill_ipaddr'), public, save :: dill_ipaddr !<-- NAME= ok here

end module mod_dill

 

View solution in original post

0 Kudos
3 Replies
andrew_4619
Honored Contributor II
735 Views

Remove ", name='dill_ipaddr'"  there is no syntax in TYPE to make an alias name in standard Fortran. 

0 Kudos
FortranFan
Honored Contributor II
736 Views

@Norman K.,

Merry Christmas.

As explained by Andrew, NAME= clause is not an option in a derived-type definition such as with your 'ipaddr' type.

Did you mean to have NAME= clause in a type declaration of a de facto 'global' object as shown below?

module mod_dill

    use, intrinsic :: iso_c_binding, only: c_char
    implicit none; private

    public :: ipaddr

    type, bind(C) :: ipaddr
        character(c_char) :: address(32)
    end type ipaddr

    type(ipaddr), bind(C, name='dill_ipaddr'), public, save :: dill_ipaddr !<-- NAME= ok here

end module mod_dill

 

0 Kudos
Norman_K_
New Contributor I
735 Views

so...

"Bind with name" an instance, but not a whole class

Makes sense, 

Thanks both

Merry Christmas

N

0 Kudos
Reply