U10215@uicvm.uic.edu (05/28/91)
Recently I bought a Borland c++; but I have never programmed in c++. One thing really bothers me for learning this language. Is there any way of using FORTRAN COMMON statement in c++? I tried fortran to C converting program (f2c) which is available in netlib. It does not help me out. Is there a book for C++ for FORTRAN programmer ? Your help in this regards is highly appreciated. Thanks, S. T. Kim
mvm@caesun6.harris-atd.com (Matt Mahoney) (05/28/91)
In article <91147.181437U10215@uicvm.uic.edu> U10215@uicvm.uic.edu writes: >Is there any way of using FORTRAN COMMON statement in c++? I assume you want to use global variables. For instance: int a; // Global main() { int a; // Local to function main } >Is there a book for C++ for FORTRAN programmer ? I like the "C++ Primer" by Lippman. The author assumes you have some programming experience, but not necessarily C. -------------------------- Matt Mahoney, mvm@epg.harris.com #include <disclaimer.h>
Matt.Mahoney@sunbrk.FidoNet.Org (Matt Mahoney) (05/29/91)
Reply-To: mvm@caesun6.UUCP (Matt Mahoney) In article <91147.181437U10215@uicvm.uic.edu> U10215@uicvm.uic.edu writes: >Is there any way of using FORTRAN COMMON statement in c++? I assume you want to use global variables. For instance: int a; // Global main() { int a; // Local to function main } >Is there a book for C++ for FORTRAN programmer ? I like the "C++ Primer" by Lippman. The author assumes you have some programming experience, but not necessarily C. -------------------------- Matt Mahoney, mvm@epg.harris.com #include <disclaimer.h> * Origin: Seaeast - Fidonet<->Usenet Gateway - sunbrk (1:343/15.0)
gary@neptune.ctc.contel.com (Gary Bisaga x4219) (05/29/91)
In article <91147.181437U10215@uicvm.uic.edu>, U10215@uicvm.uic.edu writes: > Recently I bought a Borland c++; but I have never programmed in c++. I believe this is a good choice. I too have bought BC++ and both the product and the documentation seem to be quite good. > One thing really bothers me for learning this language. > Is there any way of using FORTRAN COMMON statement in c++? Well ... the "obvious" solution (unless you're not a C programmer) is to use global variables, ones declared outside of any function. I am assuming, however that you want something a little better than variables accessible to ANY function, analogous to FORTRAN's named COMMON. There are at least a few ways of doing this. First, you can use variables declared STATIC. This keeps the variables only accessible to functions in that same source file. This is also an "obvious" C language method. Second, since named COMMON is sort of a data hiding mechanism, you could create a class for each named COMMON you use. Use private member variables for the variables in the named COMMON; make member or friend functions of the functions that use the named commons. Using multiple inheritance could make this more complete -- have classes that multiply inherit where a function needs groups of named COMMONS. Probably the best advice is to try not to do a direct comparison between COMMON and C++ constructs. Acknowledge that COMMON provides a combination data sharing and data hiding mechanism and look to see how C++ does the same two jobs (classes and inheritance). These can be very powerful once you get used to the object oriented "idea." If you want to know more about object-oriented development in general, I highly recommend the book "Object-Oriented Analysis", Second Edition, by Peter Coad. It's part of the Yourdon series, published by Prentice-Hall (ISBN 0-13-629981-4). He and Ed Yourdon also have a forthcoming book about object-oriented design that will probably be good as well. Gary Bisaga (gary@ctc.contel.com)