Prev: fortran 90/95 BNF grammar
Next: compiler bug?
From: dpb on 1 Dec 2008 17:14 George wrote: > On Mon, 01 Dec 2008 14:40:34 -0600, Gary Scott wrote: .... >> Call a C-based API from Fortran? yes, ... > > I'd sure like to see how you did that. How much of it is specific to CVF? .... Prior to implementation of the Standard C-binding every compiler has their own variant of writing the interface description for mixed language programming but afaik every compiler has some technique. Best bet is to look at the documentation for the specific compiler. A random example from CVF for the Win32 FindFirstFileEx API would use the appropriate CVF-supplied module w/ a USE KERNEL32 statement. The source from kernel32.f90 looks like .... > INTERFACE > !DEC$ IF DEFINED( _M_IX86) > FUNCTION FindFirstFileEx( & > lpFileName, & > fInfoLevelId, & > lpFindFileData, & > fSearchOp, & > lpSearchFilter, & > dwAdditionalFlags) > USE DFWINTY > integer(HANDLE) :: FindFirstFileEx ! HANDLE > !DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'FindFirstFileExA' :: FindFirstFileEx > !DEC$ ATTRIBUTES REFERENCE, ALLOW_NULL :: lpFileName > character*(*) lpFileName ! LPCSTR lpFileName > integer(ENUM) fInfoLevelId ! FINDEX_INFO_LEVELS fInfoLevelId > integer(LPVOID) lpFindFileData ! LPVOID lpFindFileData > integer(ENUM) fSearchOp ! FINDEX_SEARCH_OPS fSearchOp > integer(LPVOID) lpSearchFilter ! LPVOID lpSearchFilter > integer(DWORD) dwAdditionalFlags ! DWORD dwAdditionalFlags > END FUNCTION > END INTERFACE The module DFWINTY includes the structures and definitions of the data types. For another API, one would have to do the same thing for that particular API's interfaces as DEC/Compaq did and supplied w/ D/CVF (and I presume, most commercial vendors do for their own products). I would also presume there are appropriate modules already built for the common OS'es for the various open source compilers. --
From: George on 1 Dec 2008 19:34 On Mon, 01 Dec 2008 16:14:31 -0600, dpb wrote: > George wrote: >> On Mon, 01 Dec 2008 14:40:34 -0600, Gary Scott wrote: > ... >>> Call a C-based API from Fortran? yes, ... >> >> I'd sure like to see how you did that. How much of it is specific to CVF? > ... > > Prior to implementation of the Standard C-binding every compiler has > their own variant of writing the interface description for mixed > language programming but afaik every compiler has some technique. > > Best bet is to look at the documentation for the specific compiler. > > A random example from CVF for the Win32 FindFirstFileEx API would use > the appropriate CVF-supplied module w/ a USE KERNEL32 statement. > > The source from kernel32.f90 looks like > > ... >> INTERFACE >> !DEC$ IF DEFINED( _M_IX86) >> FUNCTION FindFirstFileEx( & >> lpFileName, & >> fInfoLevelId, & >> lpFindFileData, & >> fSearchOp, & >> lpSearchFilter, & >> dwAdditionalFlags) >> USE DFWINTY >> integer(HANDLE) :: FindFirstFileEx ! HANDLE >> !DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'FindFirstFileExA' :: FindFirstFileEx >> !DEC$ ATTRIBUTES REFERENCE, ALLOW_NULL :: lpFileName >> character*(*) lpFileName ! LPCSTR lpFileName >> integer(ENUM) fInfoLevelId ! FINDEX_INFO_LEVELS fInfoLevelId >> integer(LPVOID) lpFindFileData ! LPVOID lpFindFileData >> integer(ENUM) fSearchOp ! FINDEX_SEARCH_OPS fSearchOp >> integer(LPVOID) lpSearchFilter ! LPVOID lpSearchFilter >> integer(DWORD) dwAdditionalFlags ! DWORD dwAdditionalFlags >> END FUNCTION >> END INTERFACE > > > The module DFWINTY includes the structures and definitions of the data > types. > > For another API, one would have to do the same thing for that particular > API's interfaces as DEC/Compaq did and supplied w/ D/CVF (and I presume, > most commercial vendors do for their own products). I would also > presume there are appropriate modules already built for the common OS'es > for the various open source compilers. Wow, dpb, I've never seen windows stuff in fortran before. Thx. -- George Use power to help people. For we are given power not to advance our own purposes nor to make a great show in the world, nor a name. There is but one just use of power and it is to serve people. George W. Bush Picture of the Day http://apod.nasa.gov/apod/
From: Gary Scott on 1 Dec 2008 20:24
George wrote: > On Mon, 01 Dec 2008 14:40:34 -0600, Gary Scott wrote: > > >>>>Page 576 last itemized list item (#3). I'm assuming that it is only >>>>referring to use of pointer arithmetic on the arguments themselves (not >>>>quite sure why you might do that), not to prohibit use of pointer >>>>arithmetic internally (e.g. I use c function calls into a device driver >>>>that increments a hard coded address to operate hardware). >>> >>> >>>You do this with fortran? >>> >> >>Call a C-based API from Fortran? yes, I had to adapt 230 APIs for CVF as >>part of my master's project (all done but the binding of the thesis). I >>bet I'm the only one that used Fortran in my electronics hardware design >>Master's in the last 25 years. > > > I'd sure like to see how you did that. How much of it is specific to CVF? Should work with IVF as well. Its no different than the API access CVF already provides. In fact, one of the vendors stated it as a C API but actually used STDCALL and didnt seem to understand the difference. > > I take it your defence went well? It went pretty well. I tried to pull some criticism out of them afterwards, but didn't achieve much. The Chair might have been in a hurry to attend a meeting in Houston though. -- Gary Scott mailto:garylscott(a)sbcglobal dot net Fortran Library: http://www.fortranlib.com Support the Original G95 Project: http://www.g95.org -OR- Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html If you want to do the impossible, don't hire an expert because he knows it can't be done. -- Henry Ford |