473,804 Members | 2,111 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 3604
"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
2111
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
4360
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
5004
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
9712
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
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,...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7634
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
6862
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
5530
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...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.