469,602 Members | 1,713 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Calling a FORTRAN function that returns a complex

Hi all,

I was wondering why there is one extra argument for the return values of
complex functions. And why is this not the case with any other data
type (except char)

example :

* In case of a non complex value

=== FORTRAN ===
real function f(p)
real p
f = p
return
end
=== C-call / C++-call ===
extern float f_(float *); // for C
// extern "C" { float f_(float *); } // for C++
float r,s;
s = f_(&r);
==============

* in case of a complex value
=== FORTRAN ===
complex function f(p)
complex p
f = p
return
end
=== C-call ===
typedef struct { float r,i; } complex
extern void f_(complex *return, complex *);

complex r,s;
f_(&s,&r);
====C++ call=====
extern "C" { void f_(std::complex<float*return, std::complex<float*);

std::complex<floatr,s;
f_(&s,&r);
===================

So what is the structural reason of this difference
float f_(float *);
void f_(complex *return, complex *);
Hoping on an answer,
With kind regards
Klaas
Sep 5 '07 #1
3 3313
"Klaas Vantournhout" <no************@spam.comwrote in message
news:fb**********@gaudi2.UGent.be...
Hi all,

I was wondering why there is one extra argument for the return values of
complex functions. And why is this not the case with any other data
type (except char)

example :

* In case of a non complex value

=== FORTRAN ===
real function f(p)
real p
f = p
return
end
=== C-call / C++-call ===
extern float f_(float *); // for C
// extern "C" { float f_(float *); } // for C++
float r,s;
s = f_(&r);
==============

* in case of a complex value
=== FORTRAN ===
complex function f(p)
complex p
f = p
return
end
=== C-call ===
typedef struct { float r,i; } complex
extern void f_(complex *return, complex *);

complex r,s;
f_(&s,&r);
====C++ call=====
extern "C" { void f_(std::complex<float*return, std::complex<float*);

std::complex<floatr,s;
f_(&s,&r);
===================

So what is the structural reason of this difference
float f_(float *);
void f_(complex *return, complex *);
Look up the definitions of "real" and "imaginary" parts. That should give
you your answer.
Sep 5 '07 #2
Klaas Vantournhout <no************@spam.comwrote:
# Hi all,
#
# I was wondering why there is one extra argument for the return values of
# complex functions. And why is this not the case with any other data
# type (except char)

Between the caller values on the stack and callee values on the
stack, there is interleaved section for the function call/return
protocol. On return, the function results has to be moved over
linkage into the caller values. If the result value fits in the
registers, (such as integer or double precision), the result is
loaded there and the return executed with the caller able to
deposit the result where it wants.

If the results cannot fit in the registers due to size or brain
dead calling conventions, it typically has to be copied by the callee
to a preallocated slot in the caller; the address has to be passed
to the caller.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
No pleasure, no rapture, no exquisite sin greater than central air.
Sep 5 '07 #3
Between the caller values on the stack and callee values on the
stack, there is interleaved section for the function call/return
protocol. On return, the function results has to be moved over
linkage into the caller values. If the result value fits in the
registers, (such as integer or double precision), the result is
loaded there and the return executed with the caller able to
deposit the result where it wants.

If the results cannot fit in the registers due to size or brain
dead calling conventions, it typically has to be copied by the callee
to a preallocated slot in the caller; the address has to be passed
to the caller.
Hmm, this clearly makes sense!
Thanks for the reply.

Klaas
Sep 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Sascha T. | last post: by
12 posts views Thread by Bigdakine | last post: by
5 posts views Thread by Amit | last post: by
11 posts views Thread by RichN | last post: by
3 posts views Thread by Klaas Vantournhout | last post: by
3 posts views Thread by =?Utf-8?B?TWFyZWs=?= | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.