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

declare a type with file scope but not a module

MWind2
New Contributor III
458 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
Honored Contributor III
454 Views

No - Fortran does not have file scope.

View solution in original post

0 Kudos
7 Replies
Steve_Lionel
Honored Contributor III
455 Views

No - Fortran does not have file scope.

0 Kudos
jimdempseyatthecove
Honored Contributor III
416 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

0 Kudos
MWind2
New Contributor III
400 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.

0 Kudos
Steve_Lionel
Honored Contributor III
395 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.

0 Kudos
Steve_Lionel
Honored Contributor III
379 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".

0 Kudos
MWind2
New Contributor III
373 Views

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

0 Kudos
Reply