473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3563
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Nick Coghlan | last post by:
Thought some folks here might find this one interesting. No great revelations, just a fairly sensible piece on writing readable code :) The whole article:...
3
by: Sascha T. | last post by:
Hi! I have desperately searched google and its groups in vain. Hope you can help with my problem. I need to call some ancient Fortran objects by C++-main program with the latest Intel Compiler...
12
by: Bigdakine | last post by:
I don't know if this is the right forum for this, and if not please suggest one which fits. I have to call a fortran sub routine from a C main program. The fortran subroutine statement is ...
5
by: Amit | last post by:
I tried calling a subroutine in a fortran module from C ,but couldn't.I always get the error: undefined reference in the main.o file (main is in C calling the subroutine). for calling the...
2
by: AlanL | last post by:
I am calling a Fortran DLL that has a declaration like: character * 260 variablename. I do not have the Fortran code. A path to a file is passed to the DLL. C# does not have a fixed character...
2
by: Ray J. | last post by:
I have a C++ program written and compiled on Solaris 8 with gcc. With gcc lets me compile fortran code along with the C++ program to be able to call the fortran code as a subroutine. The...
11
by: RichN | last post by:
I am developing a c program in Visual Studio .NET 2003. I also have an Intel(R) Fortran compiler for MVS .NET My fortran sourcecode already existed. I started a new fortran project and chose to...
8
by: Luna Moon | last post by:
Hi all, As a C/C++ programmer, there are a few reasons to use Fortran: (1) Fortran is very similar to Matlab and easy to port; (2) Fortran has support of complex numbers and vectorized numbers...
3
by: Klaas Vantournhout | last post by:
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...
3
by: =?Utf-8?B?TWFyZWs=?= | last post by:
Hi As well as trying to call a fortran dll with a structure parameter from a C# front end, we are trying to do this using AssemblyBuilder and MethodInfo to do it dynamically. Ultimately this will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.