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

Re: FORTRAN character data



Christian Holm Christensen wrote:
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 :-)

http://www.jelovic.com/articles/why_java_is_slow.htm

IMHO, java is just a reflection of the 90s generation push to dumbed down
superficial easy and non-optimal solutions to everything. Teaching java
to students will only encourage more slow and bloated crap to be written.
Java is only good for web-page programmers. Science and engineering students
should learn something more useful, and they should be smarter than the
average web programmer.

Uni students should be taught C because it is easy, and shows the concepts
of stack and heap. The only problem is that there are exceptionally few lecturers
that can write decent C with a good style and teach it well.

With C, you are thinking close to the metal, so your programs are well matched
to the machine, which is good for fast and efficient code. Once you know C, most
other languages are much easier to understand (including C++).



Reply to: