RE: [Dev-C++] Mixed Language Programming w/Dev-Cpp
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Louis G. <lg...@ya...> - 2002-10-31 15:40:10
|
Hi all, I suggest we are missing the point of the original question. The original question was about mixed-language programming. i.e. a compiler that is capable of compiling a single program, one part of which is written in C and another oart in FORTRAN. GCC IS a mixed compiler. What you seem to be dealing with below is CONVERTING a program written in FORTRAN to an equivalent C/C++ program. Converting a FORTRAN program is difficult because of the fundamental differences in the way FARTRAN and C/C++ stores multi-dimentional arrays, the way parameters are passed to functions, and the way arrays are indexed (C arrays start with index zero, FORTRAN starts with 1). You have to re-write a program to convert it or use a program like 'f2C' (which in my experience works poorly) A MIXED compiler (if working correctly) is well-aware of the FORTRAN vs C/C++ differences and should compile object code for mixed programs correctly. The only thing that one has to learn is how to place, in the source code, a compiler instruction or 'switch' that tells the gcc compiler to begin and end the processing FORTRAN source code statements. I not sure how to do this with gcc. --- Per Westermark <pw...@ia...> wrote: > 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 > > > > > > > > > > > > > ------------------------------------------------------- > 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 __________________________________________________ Do you Yahoo!? HotJobs - Search new jobs daily now http://hotjobs.yahoo.com/ |