{"title":"在Fortran 2003中与C语言的互操作性","authors":"A. Donev","doi":"10.1145/1124708.1124710","DOIUrl":null,"url":null,"abstract":"One of the major new features in the Fortran 2003 is features for interoperability with C © Interop). The intrinsic module ISO_C_BINDING provides:• constants, mostly type parameters, C_NULL_CHAR, C_NULL_PTR, and others,• types, and in particular, TYPE(C_PTR) and TYPE(C_FUNPTR),• procedures, such as C_LOC, C_FUNLOC, C_F_POINTER, C_F_PROCPOINTER and C_ASSOCIATED.A Fortran interface can be specified for a C function with external linkage and used to invoke such a function. The interface has the characteristic BIND(C) label, and must also satisfy some additional restrictions.C Interop can be used to portably use multi-language codes in Fortran. Since most languages interoperate with C, the feature can actually be used to interoperate with other programming languages as well. C Interop can also be used to give access to Fortran programmers to the many standard libraries with widely-used and implemented C interfaces. This includes lower-level tasks such as interfacing with the OS on UNIX-based systems, or using special libraries like OpenGL.For simple API's, developing Fortran interfaces is practically trivial once one gets some experience. For more complicated API's whose full functionality/power is not needed, such as for example TCP/IP sockets or shared-memory segments on UNIX systems, it is often easier to develop a condensed C API/library that does the actual work, and is simpler to interface to from Fortran. However, for libraries like OpenGL, one should provide a full Fortran interface so that the whole API can be accessed. Doing this manually is not easy and is also error-prone due to the size of the OpenGL/GLU/GLUT interfaces. For certain libraries like MPI, a special Fortran interface may be defined for the purposes of efficiency, portability, ease-of-use, or to accommodate for language semantic differences.In this first paper, we will show how to develop a Fortran interface for a simple C API/library. In a second paper, we consider automating the process so that large and more complex API's, and in particular, OpenGL, can be handled. The source codes can be obtained at http://atom.princeton.edu/donev/F2x.Along the way, we identify some problems with the design of C Interop in Fortran 2003.","PeriodicalId":379614,"journal":{"name":"ACM SIGPLAN Fortran Forum","volume":"194 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2006-04-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"2","resultStr":"{\"title\":\"Interoperability with C in Fortran 2003\",\"authors\":\"A. Donev\",\"doi\":\"10.1145/1124708.1124710\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"One of the major new features in the Fortran 2003 is features for interoperability with C © Interop). The intrinsic module ISO_C_BINDING provides:• constants, mostly type parameters, C_NULL_CHAR, C_NULL_PTR, and others,• types, and in particular, TYPE(C_PTR) and TYPE(C_FUNPTR),• procedures, such as C_LOC, C_FUNLOC, C_F_POINTER, C_F_PROCPOINTER and C_ASSOCIATED.A Fortran interface can be specified for a C function with external linkage and used to invoke such a function. The interface has the characteristic BIND(C) label, and must also satisfy some additional restrictions.C Interop can be used to portably use multi-language codes in Fortran. Since most languages interoperate with C, the feature can actually be used to interoperate with other programming languages as well. C Interop can also be used to give access to Fortran programmers to the many standard libraries with widely-used and implemented C interfaces. This includes lower-level tasks such as interfacing with the OS on UNIX-based systems, or using special libraries like OpenGL.For simple API's, developing Fortran interfaces is practically trivial once one gets some experience. For more complicated API's whose full functionality/power is not needed, such as for example TCP/IP sockets or shared-memory segments on UNIX systems, it is often easier to develop a condensed C API/library that does the actual work, and is simpler to interface to from Fortran. However, for libraries like OpenGL, one should provide a full Fortran interface so that the whole API can be accessed. Doing this manually is not easy and is also error-prone due to the size of the OpenGL/GLU/GLUT interfaces. For certain libraries like MPI, a special Fortran interface may be defined for the purposes of efficiency, portability, ease-of-use, or to accommodate for language semantic differences.In this first paper, we will show how to develop a Fortran interface for a simple C API/library. In a second paper, we consider automating the process so that large and more complex API's, and in particular, OpenGL, can be handled. The source codes can be obtained at http://atom.princeton.edu/donev/F2x.Along the way, we identify some problems with the design of C Interop in Fortran 2003.\",\"PeriodicalId\":379614,\"journal\":{\"name\":\"ACM SIGPLAN Fortran Forum\",\"volume\":\"194 1\",\"pages\":\"0\"},\"PeriodicalIF\":0.0000,\"publicationDate\":\"2006-04-01\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"2\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"ACM SIGPLAN Fortran Forum\",\"FirstCategoryId\":\"1085\",\"ListUrlMain\":\"https://doi.org/10.1145/1124708.1124710\",\"RegionNum\":0,\"RegionCategory\":null,\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"\",\"JCRName\":\"\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"ACM SIGPLAN Fortran Forum","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/1124708.1124710","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 2
Interoperability with C in Fortran 2003
One of the major new features in the Fortran 2003 is features for interoperability with C © Interop). The intrinsic module ISO_C_BINDING provides:• constants, mostly type parameters, C_NULL_CHAR, C_NULL_PTR, and others,• types, and in particular, TYPE(C_PTR) and TYPE(C_FUNPTR),• procedures, such as C_LOC, C_FUNLOC, C_F_POINTER, C_F_PROCPOINTER and C_ASSOCIATED.A Fortran interface can be specified for a C function with external linkage and used to invoke such a function. The interface has the characteristic BIND(C) label, and must also satisfy some additional restrictions.C Interop can be used to portably use multi-language codes in Fortran. Since most languages interoperate with C, the feature can actually be used to interoperate with other programming languages as well. C Interop can also be used to give access to Fortran programmers to the many standard libraries with widely-used and implemented C interfaces. This includes lower-level tasks such as interfacing with the OS on UNIX-based systems, or using special libraries like OpenGL.For simple API's, developing Fortran interfaces is practically trivial once one gets some experience. For more complicated API's whose full functionality/power is not needed, such as for example TCP/IP sockets or shared-memory segments on UNIX systems, it is often easier to develop a condensed C API/library that does the actual work, and is simpler to interface to from Fortran. However, for libraries like OpenGL, one should provide a full Fortran interface so that the whole API can be accessed. Doing this manually is not easy and is also error-prone due to the size of the OpenGL/GLU/GLUT interfaces. For certain libraries like MPI, a special Fortran interface may be defined for the purposes of efficiency, portability, ease-of-use, or to accommodate for language semantic differences.In this first paper, we will show how to develop a Fortran interface for a simple C API/library. In a second paper, we consider automating the process so that large and more complex API's, and in particular, OpenGL, can be handled. The source codes can be obtained at http://atom.princeton.edu/donev/F2x.Along the way, we identify some problems with the design of C Interop in Fortran 2003.