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

declare a type with file scope but not a module

MWind2
New Contributor III
228 Views

Can I define a type for file scope without a module as in

type bounds_type
integer lb ! Lower Bound
integer ub ! Upper Bound
end type bounds_type

 

subroutine a()

!uses bounds type

end subroutine 

subroutine a()

!uses bounds type

end subroutine 

 

0 Kudos
1 Solution
Steve_Lionel
Black Belt Retired Employee
224 Views

No - Fortran does not have file scope.

View solution in original post

7 Replies
Steve_Lionel
Black Belt Retired Employee
225 Views

No - Fortran does not have file scope.

jimdempseyatthecove
Black Belt
186 Views

You could use the preprocessor or an INCLUDE file.

! must be compiled with fpp
#define  bounds type bounds_type ; integer :: lb ; integer :: ub ; end type bounds_type

program Console2
    implicit none
    print *, 'Hello World'
end program Console2

subroutine a()
    bounds
    type(bounds_type) :: bt
    bt%lb = 1
end subroutine a

subroutine b()
    bounds
    type(bounds_type) :: bt
    bt%lb = 2
end subroutine b

Note, I tried using the end of line continuation character, but that did not work. ; does work.

 

Use of the Fortran INCLUDE file would be a better approach IMHO

Jim Dempsey

MWind2
New Contributor III
170 Views

I was trying to get the SAFEARRAY dll "cleaner" and pass bounds, but the first iteration uses a module. I must have made a typo as I know now that the dll imports the use <module> routines. Latest version attached, attempt to make one sub and user gets dim and bounds to process. Later will try to get vartype from SAFEARRAY, but it does not seem in ifcon.

Steve_Lionel
Black Belt Retired Employee
165 Views

There isn't a type declared for a SAFEARRAY - the interfaces all reference it as a pointer-sized integer (in other words, an address). Because the structure is variable size, and is also "opaque", it makes more sense to treat it as an opaque pointer.

Steve_Lionel
Black Belt Retired Employee
149 Views

What do you want to do with such a type? There are functions to get and store all the values you need.

I don't understand your reference to "ifcon".

MWind2
New Contributor III
143 Views

ifcom.  I think I've found material that indicates Intel has done such already with VARIANT typing. Sorry.

Reply