Re: Variable number of arguments



<salgerman@xxxxxxxxx> wrote:
[much elided]
//void c_function(const char *fmt) // this works
void c_function(const char *fmt,...) // this does not
....
call c_function('The %s is '//nl)

Calling C from Fortran is full of portability issues. It can be done,
but there are lots of gotchas. That's why the C interop stuff is one of
the major features of f2003.

You are apparently aware of at least one aspect of the name mangling
issue. Your use of the -fno-underscoring option shows that. Be aware
that that issue has lots of variants and isn't always so easily solved.
Also, using -fno-underscoring can cause problems elsewhere because all
the code in a program needs to be compiled with that option the same
way, which is problematic if, for example, you are using 3rd party
libraries. Basically, that switch is the simplest way to avoid the
problem in some cases, but it is not a very robust way.

But your current problem is probably different. Fortran character
arguments have extra data associated with them. As long as you are just
in Fortran, that is taken care of "behind your back". When you try to
mix languages, it is visible and must be accounted for. The details *DO*
vary from compiler to compiler.

The most common scheme is to pass the address of the string as one
argument and the length in a separate argument, which the compiler
constructs for you. That extra argument is usually the length passed by
value. Sometimes the extra argument is added right after the address
one. Sometimes it is added way at the end of the list of arguments.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.



Relevant Pages

  • Re: Help from fellow Fortran Users
    ... >> department head winced and commented that Fortran is no longer being ... Portability, for programs written in any language, depends on four ... A compiler that generates code for an AXP platform is not ... Some programmers are just so impressed with their own knowledge of the ...
    (comp.lang.fortran)
  • Re: A question on Newtons Method
    ... >> I can't believe you'd advise a noob to use a compiler which is still ... > production codes and codes from textbooks. ... > The Fortran standard generally does not specify the required behavior ... >> another important class of hassle which most numerical programmers ...
    (sci.math.num-analysis)
  • Fortran Resources (July 2004)
    ... and the standard for the Fortran language and its derivatives. ... WHERE CAN I OBTAIN A FORTRAN 95 COMPILER? ... Absoft Fortran compilers, debuggers, and development tools for Windows, ... are available for Linux systems. ...
    (comp.lang.fortran)
  • Fortran Resources (August 2004)
    ... and the standard for the Fortran language and its derivatives. ... Absoft Fortran compilers, debuggers, and development tools for Windows, ... and Linux include source-compatible Fortran 95 compiler suites ... are available for Linux systems. ...
    (comp.lang.fortran)
  • Fortran Resources (Last Issue)
    ... the, then, new Fortran 90. ... and the standard for the Fortran language and its derivatives. ... WHERE CAN I OBTAIN A FORTRAN 95 COMPILER? ... The Fortran Company offers F, the subset language, for Unix and Windows, ...
    (comp.lang.fortran)