[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: FORTRAN character data (was: Re: FORTRAN common blocks)



Hi all,

On Thu, 2006-01-19 at 11:16 -0500, John W. Eaton wrote:
> On 19-Jan-2006, Brett Viren wrote:
> 
> This is not universally true.  The particular method used for passing
> character arguments in Fortran is compiler/system dependent.  

The gory details can be found in `/usr/include/cfortran/cfortran.h' from
the `cfortran' package, and the accompanying documentation.   That said,
one can usually get away with 

        Fortran77:
        ------------------------------------------------
        SUBROUTINE FOO(STR1,X,STR2)
        CHARACTER STR1*8, STR*8
        REAL	  X
        ...
        END
        
        C/C++:
        ------------------------------------------------
        #ifndef WIN32
        # define type_of_call 
        # define DEFCHARD	const char*
        # define DEFCHARL	, const int
        # define PASSCHARD(s)	s
        # define PASSCHARL(s)	, strlen(s)
        # define foo		foo_
        #else
        # define type_of_call	_stdcall
        # define DEFCHARD	const char*, const int
        # define DEFCHARL	
        # define PASSCHARD(s)	s, strlen(s)
        # define foo		FOO
        #endif
        extern "C"
        {
          void foo(DEFCHARD,float&,DEFCHARD DEFCHARL DEFCHARL);
        }
        
        void 
        bar(const char* str1, float x, const char* str2) 
        {
          foo(PASSCHARD(str1), x, PASSCHARD(str2) PASSCHARL(str1) PASSCHARL(str2));
        }
        


> GNU Autoconf has some macros to help with determining how underscores
> are used. 

But, if the user passes FFLAGS='-fno-second-underscore' then what?  Of
course, you can get it to work nicely - but it does take a bit of work. 

I'm surprised you guys are comparing Fortran77 to C - after all, both
are fairly old, imperative languages - perhaps you should rather compare
C, Fortran77, Pascal, ... what not to more modern languages like C++,
Java, C#(?), ML, not to mention INTERCAL :-)   After all, there's more
differences between those kind of languages then between C and
Fortran77, and whether one is pass-by-value or pass-by-reference.  

The point is always to choose the best language for the job - I'd be
stupid to write firmware in C++ - VHDL is better at expressing that.
I'd be stupid to write a Fortran77 program to parse text - Perl is much
better for that.   I'd be stupid to write vast number crunching in a
relatively slow language like Java or heaven forbid C#! 

If anyone asked me what I think science students should be taught
initially, I'd say Java - not that I'm a Java fan or even write code in
it - it's just a very clean modern language. 10-20 years ago I'd have
said Pascal (actually I wouldn't have said that, some one older that me
would have said that) for the same reasons.    Suggesting to teach
students ugly languages like C, C++, Fortran{77,90,95}, C#, and similar
is not I good idea in my mind.    Students need to know the basic
concepts of programming, and they get that from Java.   The other
languages are harder to learn this from, as there are so many technical
pit-falls, like memory allocation, argument aliasing, and what not. 

That said, I'd prefer not to see another line of Fortran for the rest of
my life :-)


Yours,

-- 
 ___  |  Christian Holm Christensen 
  |_| |  -------------------------------------------------------------
    | |  Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|           DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|            Denmark                    Office: (+45) 353  25 404
 ____|   Email:   cholm@nbi.dk               Web:    www.nbi.dk/~cholm
 | |



Reply to: