Fortran pointer
Author: h | 2025-04-25
Fortran function: pointer as actual argument and target as formal. 4. Nullifying Pointers in Fortran. 2. array of pointers fortran. 2. passing pointer arguments in fortran. 2. Pass pointer of child type to dummy argument that takes a pointer of parent class. 2. Fortran pointer to parameter array target. 3. Fortran structures and pointers. 1. One pointer for different types Fortran. 1. Fortran: Type containing a member that is an array of elements of this type. 4. Fortran polymorphism in pointers. 3. Fortran pointer attribute to type declarations. 2. How to use structures with pointers in Fortran like in C? 3.
Understanding Fortran pointers - Help - Fortran Discourse
PROCEDURE statement in the derived type declaration, the developer can make the "this" argument to be second, third, or wherever appropriate on the dummy argument list; it doesn't have to be first. Also, the argument can be named "this", "self", "me", etc. - whatever naming convention is preferred. Izaak Beekman wrote:...If one were to give the TBP/procedure-pointer component the nopass attribute then the procedure could be invoked explicitly passing the object: obj%method(obj). ...In such a case, the invocation becomes analogous to that of a conventional Fortran subprogram: CALL method(obj,..) in the case of a subroutine and foo = method(obj,..) for a function. Izaak Beekman wrote:Yeah, how they arrived at some of the finer points of the syntax for procedure pointer components really seems non-intuitive to me.Things start to make a little bit of sense to me when I consider what would be required for consistency with legacy FORTRAN. I assume that is what the Fortran 2003 standard writers had to contend with, trying to add new features while retaining syntax that, at a base level, is not alien to how it has been done since FORTRAN IV perhaps, or definitely FORTRAN 77. Considering all the constraints that any standards body would normally face and when one piles all the legacy stuff on top of it, I think Fortran 2003 creators did a remarkable job. But for many Fortran 2003 and 2008 features, I don't think I'll be writing any new code in Fortran! Thank you all for enlightening discussions on this subject. The code provided by FortranFan works like a charm. I have to admit that I would have never be able guess the correct syntax in this case, regardless of the modern FORTRAN bibliography worldwide available. The most puzzling for me is the presence of 'this' at lines 4, 8 and 12.RakFortranFan wrote:Quote:jimdempseyatthecove wrote: ... And assume the user wishes to pass the "this" pointer... Could the user then explicitly declare the "this" pointer in the function interface? ... Jim,Is the functionality shown in the code below what you're asking about? It is standard Fortran. module pcf_mod type ::
Pointers / Free Literature on Fortran - Fortran Discourse
Type related lines it compiles fine. It seems that I am stuck.Rak As you found out, you have to use a derived type here. Fortran doesn't have the notion of an array of pointers.The new error is simply a compiler bug. For some reason it thinks you're declaring a type-bound procedure, which you aren't. That's just weird - I will report it to the developers. Steve Lionel (Intel) wrote:The new error is simply a compiler bug. For some reason it thinks you're declaring a type-bound procedure, which you aren't. That's just weird - I will report it to the developers.Steve, according to Fortran 95/2003 by M,R,C this is correct behavior: When a procedure pointer component (or a type-bound procedure, Section 16.6) is invoked the object through which it is invoked is normally passed to the procedure as its first actual argument and the items in the parenthesized list are the other actual arguments. This could be undesirable; for instance, it might be wished to pass the object to a dummy argument other than the first or not to pass it at all.Therefore, I don't think this is a compiler bug. For the OP to get the intended behavior, simply add the nopass attribute to the procedure pointer declaration in the derived type: type :: ARRPROCPOINTER procedure(USERFUNC_int), pointer, nopass :: pcf end type ARRPROCPOINTER Well, I'll be darned. I'm always learning something new about this language.... Indeed you are correct, Zaak. Yeah, how they arrived at some of the finer points of the syntax for procedure pointer components really seems non-intuitive to me. Zaak,Assuming the nopass technique corrects the compiler complaint of compliance to the standard... And assume the user wishes to pass the "this" pointer... Could the user then explicitly declare the "this" pointer in the function interface?Jim Dempsey jimdempseyatthecove wrote:Zaak,Assuming the nopass technique corrects the compiler complaint of compliance to the standard... And assume the user wishes to pass the "this" pointer... Could the user then explicitly declare the "this" pointer in the function interface?Jim DempseyJim, I'm not sure what you mean by the "this" pointer. If the userFortran pointers, and aliasing - Help - Fortran Discourse
ROCHESTER HILLS, Mich., Aug. 11, 2004 (PRIMEZONE) -- Absoft Corporation has announced immediate availability of its new high performance Pro Fortran tool kit version 9.0 for Macintosh OS X. Absoft's Pro Fortran Compiler Suite is the most complete Macintosh Fortran tool kit available from any vendor and includes: Fortran 95 and C/C++ compilers, a powerful Integrated Development Environment, the market-leading Fx2(tm) Debugger, and free graphics libraries. Pro Fortran is fully compatible with Panther, all Apple tools and libraries and is specially optimized for the G5 processor.The Absoft Pro Fortran Compiler Suite for Macintosh OS X is the world's most popular Fortran tool kit for OS X and is the only environment designed specifically for creating and maintaining Fortran and C/C++ applications on Macintosh systems. Absoft's powerful and flexible Integrated Development Environment (IDE) is included at no additional charge with all versions of Pro Fortran for Macintosh (and Windows). The Absoft IDE is a stand-alone tool suite that provides graphical interfaces for multiple compilers for OS X (Pro Fortran, IBM XL Fortran, IBM XL C/C++, and gcc) and select third party tools and libraries (VAST, IMSL, 2D/3D graphics, LAPACK90)."Pro Fortran v9.0 for Macintosh OS X is Absoft's best release ever," said Wood Lotz, President of Absoft. "This exciting new tool suite includes across-the-board improvements for all components - the compiler includes new Fortran 2003 features and generates up to 25% faster code, Fx2, the leading Fortran debugger is now included and now supports the IBM XL compilers. Further, this release includes an improved editor and the only IDE available for Mac OS X which supports compilers from multiple vendors (Absoft, IBM and gnu) and select third party tools.""Absoft leads the industry in price/performance solutions with fast, reliable compilers, flexible licensing policies, powerful debugging and development tools, and free technical support," continued Lotz. "Absoft is the only company offering source compatible Fortran compilers for all of today's leading computing platforms running Windows, OS X, and Linux. This compatibility is important for users such as universities and labs who work in multiple environments," added Lotz. "Our powerful and unique combination of superior performance,. Fortran function: pointer as actual argument and target as formal. 4. Nullifying Pointers in Fortran. 2. array of pointers fortran. 2. passing pointer arguments in fortran. 2. Pass pointer of child type to dummy argument that takes a pointer of parent class. 2. Fortran pointer to parameter array target. 3. Fortran structures and pointers. 1. One pointer for different types Fortran. 1. Fortran: Type containing a member that is an array of elements of this type. 4. Fortran polymorphism in pointers. 3. Fortran pointer attribute to type declarations. 2. How to use structures with pointers in Fortran like in C? 3.Ownership for Fortran pointers - Language enhancement - Fortran
Hi,I am trying to construct a static array of procedure pointers like this: abstract interface function USERFUNC_int (arg) integer USERFUNC_int integer, intent(IN) :: arg end function USERFUNC_int end interface procedure(USERFUNC_int), pointer :: pcfs(100) but the compiler complains about the "(":error #5082: Syntax error, found '(' when expecting one of: , ; => procedure(USERFUNC_int), pointer :: pcfs(100)It is possible to declare a static array of procedure pointers? I am using ifort 13.1.3.0.Thanks,Rak Intel® Fortran Compiler 1 Solution jimdempseyatthecove wrote:... And assume the user wishes to pass the "this" pointer... Could the user then explicitly declare the "this" pointer in the function interface?...Jim,Is the functionality shown in the code below what you're asking about? It is standard Fortran. module pcf_mod type :: ARRPROCPOINTER procedure(USERFUNC_int), pointer, pass(this) :: pcf end type ARRPROCPOINTER abstract interface function USERFUNC_int (arg, this) import :: ARRPROCPOINTER integer USERFUNC_int integer, intent(IN) :: arg class(ARRPROCPOINTER) :: this end function USERFUNC_int end interface type(ARRPROCPOINTER) :: pcfs(100) end module pcf_mod program p .. integer :: i, j, k .. pcfs(i)%pcf => foo .. k = pcfs(i)%pcf(j) .. end program pNote how the interface has been changed to refer to the invoking object via the "this" dummy argument. You may also know that by using the PASS attribute in the PROCEDURE statement in the derived type declaration, the developer can make the "this" argument to be second, third, or wherever appropriate on the dummy argument list; it doesn't have to be first. Also, the argument can be named "this", "self", "me", etc. - whatever naming convention is preferred. All forum topics Previous topic Next topic 13 Replies Moreover, if I am trying to circumvent the problem by embedding the function pointer into a derived type as follows module pcf_mod abstract interface function USERFUNC_int (arg) integer USERFUNC_int integer, intent(IN) :: arg end function USERFUNC_int end interface type :: ARRPROCPOINTER procedure(USERFUNC_int), pointer :: pcf end type ARRPROCPOINTER type(ARRPROCPOINTER) :: pcfs(100) end module pcf_modI am getting a totally unrelated compiler error:error #8262: The passed-object dummy argument must be dummy data object with the same declared type as the type being defined. [ARG] function USERFUNC_int (arg)Removing thePointers in Fortran - Stack Overflow
Did want to pass the object as an actual argument to type bound procedure (TBP) or procedure being pointed to by the procedure pointer component, then the canonical way of doing this is to specify the first dummy argument of the procedure as being type-compatible with the encompassing "this" object and without adding any pass or nopass attributes to the component specification. If the procedure had only this one dummy argument, then when it is invoked via the TBP or procedure-pointer component, the encompassing object is implicitly passed as the first actual argument, and the user can invoke the procedure with no (explicit) actual arguments. e.g., obj%method(). If one were to give the TBP/procedure-pointer component the nopass attribute then the procedure could be invoked explicitly passing the object: obj%method(obj). These two scenarios are identical. In general I think explicit is better than implicit, but in this context it is reasonable to expect a procedure bound to an object to modify the objects state and appreciate the decrease in verbosity associated with this language feature.So, if I correctly understand your question, the answer is 'yes.' At any rate, between this post and Fortran Fan's hopefully we've covered the ins and outs of the pass(_____) and nopass attribute, and objects implicitly or explicitly passed as actual arguments to their TBPs/procedure-pointer components. jimdempseyatthecove wrote:... And assume the user wishes to pass the "this" pointer... Could the user then explicitly declare the "this" pointer in the function interface?...Jim,Is the functionality shown in the code below what you're asking about? It is standard Fortran. module pcf_mod type :: ARRPROCPOINTER procedure(USERFUNC_int), pointer, pass(this) :: pcf end type ARRPROCPOINTER abstract interface function USERFUNC_int (arg, this) import :: ARRPROCPOINTER integer USERFUNC_int integer, intent(IN) :: arg class(ARRPROCPOINTER) :: this end function USERFUNC_int end interface type(ARRPROCPOINTER) :: pcfs(100) end module pcf_mod program p .. integer :: i, j, k .. pcfs(i)%pcf => foo .. k = pcfs(i)%pcf(j) .. end program pNote how the interface has been changed to refer to the invoking object via the "this" dummy argument. You may also know that by using the PASS attribute in theFORTRAN 90: POINTERS - gatech.edu
Free Download Approximatrix Simply Fortran 3.39.4394 Full Version - A powerful and comprehensive editor for Fortran language.Free Download Approximatrix Simply Fortran full version standalone offline Windows installer is a powerful and comprehensive editor for Fortran language.Overview of Approximatrix Simply FortranThis is a powerful and comprehensive editor software for the Fortran programming language. This software is known as a complete and reliable Fortran compiler, utilizing the necessary productivity tools that experts need.The software package in front of you includes a configured Fortran compiler and an integrated development environment, including an integrated debugging set of other development needs.Moreover, you will have access to a powerful editor using the Simply Fortran product. This way, you can manage your projects professionally using the software. This means that this software can manage and edit your projects better than ever, given its professional capabilities.Features of Approximatrix Simply FortranBenefit from a simple Windows startup pageAbility to create and display types of charts, bars, or two-dimensional chartsBenefit from AppGraphics library in Windows versionFull support for this software from OpenMPQuick Search in Windows allows you to do thisSupport for Syntax Legacy and Modern FortranTechnical Details and System RequirementsSupported OS: Windows 11, Windows 10, Windows 8.1, Windows 7RAM (Memory): 2 GB RAM (4 GB recommended)Free Hard Disk Space: 200 MB or morePrevious versionFile Name:Approximatrix Simply Fortran 3.39.4385Version:3.39.4385File Name:Approximatrix Simply Fortran 3.38.4350Version:3.38.4350File Name:Approximatrix Simply Fortran 3.38.4338Version:3.38.4338File Name:Approximatrix Simply Fortran 3.37.4300Version:3.37.4300Comments. Fortran function: pointer as actual argument and target as formal. 4. Nullifying Pointers in Fortran. 2. array of pointers fortran. 2. passing pointer arguments in fortran. 2. Pass pointer of child type to dummy argument that takes a pointer of parent class. 2. Fortran pointer to parameter array target. 3. Fortran structures and pointers. 1. One pointer for different types Fortran. 1. Fortran: Type containing a member that is an array of elements of this type. 4. Fortran polymorphism in pointers. 3. Fortran pointer attribute to type declarations. 2. How to use structures with pointers in Fortran like in C? 3.Comments
PROCEDURE statement in the derived type declaration, the developer can make the "this" argument to be second, third, or wherever appropriate on the dummy argument list; it doesn't have to be first. Also, the argument can be named "this", "self", "me", etc. - whatever naming convention is preferred. Izaak Beekman wrote:...If one were to give the TBP/procedure-pointer component the nopass attribute then the procedure could be invoked explicitly passing the object: obj%method(obj). ...In such a case, the invocation becomes analogous to that of a conventional Fortran subprogram: CALL method(obj,..) in the case of a subroutine and foo = method(obj,..) for a function. Izaak Beekman wrote:Yeah, how they arrived at some of the finer points of the syntax for procedure pointer components really seems non-intuitive to me.Things start to make a little bit of sense to me when I consider what would be required for consistency with legacy FORTRAN. I assume that is what the Fortran 2003 standard writers had to contend with, trying to add new features while retaining syntax that, at a base level, is not alien to how it has been done since FORTRAN IV perhaps, or definitely FORTRAN 77. Considering all the constraints that any standards body would normally face and when one piles all the legacy stuff on top of it, I think Fortran 2003 creators did a remarkable job. But for many Fortran 2003 and 2008 features, I don't think I'll be writing any new code in Fortran! Thank you all for enlightening discussions on this subject. The code provided by FortranFan works like a charm. I have to admit that I would have never be able guess the correct syntax in this case, regardless of the modern FORTRAN bibliography worldwide available. The most puzzling for me is the presence of 'this' at lines 4, 8 and 12.RakFortranFan wrote:Quote:jimdempseyatthecove wrote: ... And assume the user wishes to pass the "this" pointer... Could the user then explicitly declare the "this" pointer in the function interface? ... Jim,Is the functionality shown in the code below what you're asking about? It is standard Fortran. module pcf_mod type ::
2025-04-15Type related lines it compiles fine. It seems that I am stuck.Rak As you found out, you have to use a derived type here. Fortran doesn't have the notion of an array of pointers.The new error is simply a compiler bug. For some reason it thinks you're declaring a type-bound procedure, which you aren't. That's just weird - I will report it to the developers. Steve Lionel (Intel) wrote:The new error is simply a compiler bug. For some reason it thinks you're declaring a type-bound procedure, which you aren't. That's just weird - I will report it to the developers.Steve, according to Fortran 95/2003 by M,R,C this is correct behavior: When a procedure pointer component (or a type-bound procedure, Section 16.6) is invoked the object through which it is invoked is normally passed to the procedure as its first actual argument and the items in the parenthesized list are the other actual arguments. This could be undesirable; for instance, it might be wished to pass the object to a dummy argument other than the first or not to pass it at all.Therefore, I don't think this is a compiler bug. For the OP to get the intended behavior, simply add the nopass attribute to the procedure pointer declaration in the derived type: type :: ARRPROCPOINTER procedure(USERFUNC_int), pointer, nopass :: pcf end type ARRPROCPOINTER Well, I'll be darned. I'm always learning something new about this language.... Indeed you are correct, Zaak. Yeah, how they arrived at some of the finer points of the syntax for procedure pointer components really seems non-intuitive to me. Zaak,Assuming the nopass technique corrects the compiler complaint of compliance to the standard... And assume the user wishes to pass the "this" pointer... Could the user then explicitly declare the "this" pointer in the function interface?Jim Dempsey jimdempseyatthecove wrote:Zaak,Assuming the nopass technique corrects the compiler complaint of compliance to the standard... And assume the user wishes to pass the "this" pointer... Could the user then explicitly declare the "this" pointer in the function interface?Jim DempseyJim, I'm not sure what you mean by the "this" pointer. If the user
2025-04-12Hi,I am trying to construct a static array of procedure pointers like this: abstract interface function USERFUNC_int (arg) integer USERFUNC_int integer, intent(IN) :: arg end function USERFUNC_int end interface procedure(USERFUNC_int), pointer :: pcfs(100) but the compiler complains about the "(":error #5082: Syntax error, found '(' when expecting one of: , ; => procedure(USERFUNC_int), pointer :: pcfs(100)It is possible to declare a static array of procedure pointers? I am using ifort 13.1.3.0.Thanks,Rak Intel® Fortran Compiler 1 Solution jimdempseyatthecove wrote:... And assume the user wishes to pass the "this" pointer... Could the user then explicitly declare the "this" pointer in the function interface?...Jim,Is the functionality shown in the code below what you're asking about? It is standard Fortran. module pcf_mod type :: ARRPROCPOINTER procedure(USERFUNC_int), pointer, pass(this) :: pcf end type ARRPROCPOINTER abstract interface function USERFUNC_int (arg, this) import :: ARRPROCPOINTER integer USERFUNC_int integer, intent(IN) :: arg class(ARRPROCPOINTER) :: this end function USERFUNC_int end interface type(ARRPROCPOINTER) :: pcfs(100) end module pcf_mod program p .. integer :: i, j, k .. pcfs(i)%pcf => foo .. k = pcfs(i)%pcf(j) .. end program pNote how the interface has been changed to refer to the invoking object via the "this" dummy argument. You may also know that by using the PASS attribute in the PROCEDURE statement in the derived type declaration, the developer can make the "this" argument to be second, third, or wherever appropriate on the dummy argument list; it doesn't have to be first. Also, the argument can be named "this", "self", "me", etc. - whatever naming convention is preferred. All forum topics Previous topic Next topic 13 Replies Moreover, if I am trying to circumvent the problem by embedding the function pointer into a derived type as follows module pcf_mod abstract interface function USERFUNC_int (arg) integer USERFUNC_int integer, intent(IN) :: arg end function USERFUNC_int end interface type :: ARRPROCPOINTER procedure(USERFUNC_int), pointer :: pcf end type ARRPROCPOINTER type(ARRPROCPOINTER) :: pcfs(100) end module pcf_modI am getting a totally unrelated compiler error:error #8262: The passed-object dummy argument must be dummy data object with the same declared type as the type being defined. [ARG] function USERFUNC_int (arg)Removing the
2025-04-06