Re: Variable number of arguments
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Thu, 22 Feb 2007 10:58:31 -0800
<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
.
- Follow-Ups:
- Re: Variable number of arguments
- From: glen herrmannsfeldt
- Re: Variable number of arguments
- From: salgerman
- Re: Variable number of arguments
- References:
- Variable number of arguments
- From: salgerman
- Variable number of arguments
- Prev by Date: Re: reading lines with trailing white spaces
- Next by Date: Re: what to buy now?
- Previous by thread: Variable number of arguments
- Next by thread: Re: Variable number of arguments
- Index(es):
Relevant Pages
|