473,796 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<fl oat*);

std::complex<fl oatr,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 3602
"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<fl oat*);

std::complex<fl oatr,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
2104
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: http://www.acmqueue.com/modules.php?name=Content&pa=showpage&pid=271&page=1 The section specifically on white space: http://www.acmqueue.com/modules.php?name=Content&pa=showpage&pid=271&page=3 Cheers,
3
8975
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 V8.1 on Linux 2.6.x. Compilers are properly installed and working, means, LD_LIBRARY_PATH and PATH is set correctly. Calling Fortan (example.f) from C (main.c) works fine using
12
2909
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 wload(starttime, duration, station, component, dataray, nsamp, calib, srate, samplength, datadir)
5
4358
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 subroutine I used the following name: modulename_MP_subroutinename_(...) and all possible variant (upper case,lower case).Can anybody help (for a unix system)
2
5002
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 length. I can use vba or vb6 with Dim variablename as String * 260 and it works. However, I can not get this to work in C#. The DLL returns a value denoting that the file is not found. I even concatenated spaces to the string to make sure it...
2
2825
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 specifications for this project have changed and I am porting the C++ code to Visual C++. Is there a way to call fortran code from a C++ program compiled with Visual C++?
11
543
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 create a dynamic link library. The beginning of the fortran code looks like: SUBROUTINE SFTCK3 !DEC$ ATTRIBUTES DLLEXPORT::SFTCK3
8
2090
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 and the operations in Fortran are naturally element-wise, operating on a whole vector. (3) There are many scientific codes are in Fortran.
3
1062
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 of a non complex value
3
1804
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 be done using a configuration file, but in the first instance I am trying to do this using code. The FORTRAN structure looks like this: TYPE Type1 ! Scalars plus fixed dimension arrays SEQUENCE
0
9527
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10003
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.