RE: [Dev-C++] Mixed Language Programming w/Dev-Cpp
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2002-10-30 12:11:57
|
When you have declared double a[10][10] it is quite important to know in which order the individual values are stored in memory, when trying to interface between two languages. If your C program does a[x][y] and your Fortran program has do do a[z][y] to reach the same entry. No problem when you have all three index variables available. However, when you take a pointer to a an entry inside the array, the operation might be seen as a projection down to an array with fewer dimensions. Obviously, if the entry order in memory has been transposed, the such a projection will fail misserably when switching languages. The sender thought it sent a row, but the receiver got a column. When people originally started to push for the C language, the above problem gave rise to a related problem. When referencing large memory structures, it is important to assure that the code uses locality of reference and doesn't jump around everywhere in the data. Large linear packages are always implemented so that they process entries in the same order that they are stored in memory. When converting such an algorithm - might be thousands uppon thousands of lines of code - it isn't s easy to just try and adjust for row/column switches. The result is that a C translation of a Fortran algorithm might loose 10-30% or maybe more of the speed when the same Fortran algorithm was run. The mathematical world decided that C was a slower language :-) Nowadays, there are a lot of good algorithms originally written for C, so this issue shouldn't be a problem anymore. But still, there are some billion Fortran lines of optimized and very advanced mathematics algorithms out there. /Per W On Wed, 30 Oct 2002, Marc Heiligers wrote: > To Ioannis, > > Funny thing is I was reading an old Turbo C reference guide I have lying > around that mentioned linking Turbo C and Turbo Fortran (was it called > that?). Borland seemed to very proud of this cross language linking. There > are some difficulties with function name decoration and what-not that you > need to be aware of. I can't quite recall what they were, but I'll try to > remember to take a look this evening. > > I'm not sure if the same advice will apply here since it is clearly > different compilers, but it may give you an idea. I'd still look on the net > for info specific to the compilers you want to use. > > To Per, > Is there anything you don't know anything about? (LOL). > > I don't recall if the above mentioned book mentioned any difficulties with > multi-dimensional arrays. Besides, as far as I'm aware, C uses arrays of > arrays and not multi-dimensional arrays, so would the trick not be to set > your arrays up in the same way that Fortran does? > > _____________________________ > Marc Heiligers > > > -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: 30 October 2002 11:40 AM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: RE: [Dev-C++] Mixed Language Programming w/Dev-Cpp > > > I think there might be acoule of gotchas more to think about. > > Doesn't fortran have the reversed row/column order for multi-dimensional > arrays? > > Anyway, I assume that there already exists excellent FAQ documents for this > kind of problems. > > /Per W > > On Wed, 30 Oct 2002, Ioannis Vranos wrote: > > > > -----Original Message----- > > > From: dev...@li... > > > [mailto:dev...@li...] On Behalf > > > Of Scott Williams > > > Sent: Tuesday, October 29, 2002 10:34 PM > > > To: Dev-Cpp-Users@Lists. Sourceforge. Net > > > Subject: [Dev-C++] Mixed Language Programming w/Dev-Cpp > > > > > > > > > Hi, > > > > > > Wondering if anyone has experience with mixed language programming > > > and whether it can be done with Dev-Cpp? > > > > > > In particular, I'm writing a mathematical simulation in C > > > (using Dev-Cpp) > > > and would like to make using of some existing numerical > > > routines in Fortran. > > > My C knowledge is necessity-based self-taught and so limited; > > > don't know > > > anything about Fortran. Neither do I know much about using > > > compilers/linkers/etc in command line mode (which is why I > > > use Dev-Cpp--I > > > let it worry about that stuff). > > > > > > Still, I know that built-in to the gcc interface is the g77 > > > compiler so > > > there must be a way to compile the fortran source to an > > > object with g77 and > > > then link to & call the routines from C. Could it be as > > > simple as added > > > fortran source files to my Dev-Cpp project? If so, any > > > thoughts on how to > > > prototype the Fortran functions & subfunctions to make them > > > accessible to > > > the C calling routines? > > > > > > Well if you download the whole MINGW distribution it contains a > > Fortran compiler. In theory as i can think of it, if you compile your > > fortran source code files to .o files and use C-style declarations of > > those functions in your C source code, you should be able to use them. > > > > > > Ioannis > > > > * Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > > * Alternative URL: http://run.to/noicys > > > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by:ThinkGeek > > Welcome to geek heaven. > > http://thinkgeek.com/sf > > _______________________________________________ > > Dev-cpp-users mailing list Dev...@li... > > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > |