COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### const argument in C interope with Fortran

• Email
• Follow

I have this function in C
void func1 (const int * arg1, const int arg2)

To call the C function in Fortran, I'm not sure which interface is
correct:

subroutine func1 (arg1, arg2)
integer(c_int), intent(IN) :: arg1
integer(c_int), intent(IN), value :: arg2
end

or

subroutine func1 (arg1, arg2)
integer(c_int), intent(IN) :: arg1
integer(c_int), value :: arg2
end

And the final one is how about this situation: const void*   and const
void**
How we map these objects in Fortran?

Thanks,
Tuan

 0
Reply 6/11/2010 1:33:04 AM

See related articles to this posting

bio_amateur <hoangtrongminhtuan@gmail.com> wrote:
> I have this function in C
> void func1 (const int * arg1, const int arg2)

> To call the C function in Fortran, I'm not sure which interface is
> correct:

> subroutine func1 (arg1, arg2)
>  integer(c_int), intent(IN) :: arg1
>  integer(c_int), intent(IN), value :: arg2
> end

> or

> subroutine func1 (arg1, arg2)
>  integer(c_int), intent(IN) :: arg1
>  integer(c_int), value :: arg2
> end

As I understand const, it restricts what the callee will do
with the specified variable.  There is no requirement that
the caller supply an appropriately const value, but it is
allowed to do so.

That said, there is also the difference between const int *
and int * const, and, for that matter, const int * const.

For a non-pointer actual argument, as you show, intent(in)
means that the variable itself won't be modified by the called
routine.  That is, as you say, int const *.

For a pointer argument, intent applies to the pointer,
not to the pointee.  That is, like int * const.

Note that you could also use

type(c_ptr),value :: arg1

In which case the actual argument would be c_loc() of the
appropriate array.

> And the final one is how about this situation: const void*
> and const void**

Fortran doesn't usually use void**, though it should be
possible to have an array of type(c_ptr).

In that case, intent(in) would correspond to

void**const, and not void *const* or const void**.

-- glen

 0
Reply glen 6/11/2010 2:53:56 AM

1 Replies
200 Views

Similar Articles

12/12/2013 8:39:09 PM
[PageSpeed]

 Reply:

Similar Artilces:

Passing arguments from C++ to Fortran (F77)
Hello, I am collaborating with another programmer. I need to call a Fortran function he is going to implement. I will need to pass a lot of input variables and the interface will change with time. The interface needs to be specified on both ends and will first be matched at link time. My worry is that I will not manage to keep the two interfaces consistent. I therefore been pondering about making a simple interface file, e.g: Point float:x float:y float:z and then make a program that generates a header file with a struct on the C++ side: extern "C" { struct { float x, y, z;...

Which version of Intel Fortran 1st had C Interop?
Does anyone know which version of Intel Fortran was the first one to have C interop capability? James Tursa James Tursa <aclassyguywithaknotac@hotmail.com> wrote: > Does anyone know which version of Intel Fortran was the first one to > have C interop capability? I don't know the answer to your question, but I suspect that there are 2 different answers depending on exactly what you mean by the question. Namely 1. If you mean C interop capability as a general term, I suspect that goes back a long ways, perhaps to the first version. 2. You might mean specific...

C- Fortran interface
Hi I am facing a problem while calling a C function with variable number of arguments from Fortran. Since the C function has variable number of arguments and also the range of arguments is not fixed it might be difficult task to create a wrapper (although in C) to enable callability from Fortran. My C function is defined as void addMessage(int msgNo, ...) Here the three dots after the first mandatory argument is an essential syntax for C variable arguments. Right now i am in a fix as to how to go abt writing a wrapper for fortran. Any inputs or suggestions in this regard are most welcome. R...

vb calling C function wit argument const int * ?
I am interested calling netCDF package from VB6 (or VBA Excel) I have a C DLL: (and source) Here an exemple of function: ================================== int nc_def_var( int ncid, const char *name, nc_type type, , const int *dimids, int *varidp) { .... } ================================== Generally I have no problem, I have success interfacing with VB (yes I use __stdcall etc.) I have no probleme with int ncid => ByVal const char *name => ByVal nc_type type => ByVal int *varidp => ByRef but with argument "const int *" I have big tro...

Fortran Vs C, C++, C#
What can Fortran do that C, C++, C# can't? Along similar lines where would Fortran be a superior chice over C, C+ +, or C# Jeff RF ENGINEER55 > What can Fortran do that C, C++, C# can't? > > Along similar lines where would Fortran be a superior chice over C, C+ > +, or C# None that I know of. Here is a dated (1992) paper comparing F77, F90, C and C++ for engineering pgrograms: http://www.leshatton.org/Documents/JSX_0192.pdf Me, myself and I, we all prefer C++. I like strong typing and mandatory function prototypes. I also like function overloa...

Many Fortran code! How to call Fortran code from C/C++?
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. ------------- So how do I call Fortran program from my C program? I am using MSVS. NET 2003, VisualC++ and Intel C++ therein, and also the Intel Visual Fortran therein. To give an example, I want to call a Fortran program from C++, which is in its bare form, it ...

Passing an array from FORTRAN to C then passing it within C and Returning it to FORTRAN
Im trying to read an xml file. What happens is that I have a FORTRAN program that calls a C library that uses libxml2 to read an xml file. The passed array (from FORTRAN) needs to be passed to several functions within the C program before being returned to the FORTRAN program. My question is how do I pass the array within C and how do I return the array to FORTRAN. The code: #include <stdio.h> #include <libxml/parser.h> #include <libxml/tree.h> #include <libxml/xmlstring.h> #include <libxml/xpath.h> #ifdef LIBXML_TREE_ENABLED static void get_ite...

Casm -- calling Fortran from C and C++
Chasm Language Interoperability Tools http://chasm-interop.sourceforge.net/ Does anybody have experience with Chasm? Opinions? "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> wrote in message news:<cg63u2$ne9$1@nntp1.jpl.nasa.gov>... > Chasm Language Interoperability Tools > > http://chasm-interop.sourceforge.net/ > > Does anybody have experience with Chasm? Opinions? I evaluated the chasm for a relatively large industrial project. I prepared a 12 page report documenting my experience (unfortunately I cannot share it with you since it is a com...

\let control sequence in argument to c.s. in argument
Hi. I'm trying to declare a command as follows: \DeclareVarSymbol{epsilon}{varepsilon} which will \let\epsilon\varepsilon. Now I got to \expandafter\let\expandafter\epsilon\csname #2\endcsname which will expand to \let\epsilon\varepsilon but I can't seem to get the \epsilon to be read from the first argument. I presume it would be something like \expandafter\let\expandafter\csname #1\endcsname\csname #2\endcsname but then it get's a mess because the arguments to \expandafter don't get expanded in the order I would like to. Any help would be appreciated...

Modifying Fortran strings in C and then passing them back to Fortran
All: I'm trying to modify some strings from Fortran in C and then reuse the modified string back in Fortran. So far I've been able to successfully do it with one string at a time. The way I do it with one string is to return the C pointer that points to the modified string and then use C_F_POINTER to convert it to a F pointer and then I create a string out of that pointer. This is done below: MODULE mymod USE ISO_C_BINDING IMPLICIT NONE INTERFACE TYPE(C_PTR) FUNCTION ctester3(string) BIND(C, NAME="ctester3") USE ISO_C_BINDING CHARACTER(KIND=C_CHAR) :: strin...

test suite to validate POD argument passing between C and C++
Hello, Is there a test suite to validate that we are able to successfully pass POD (plain old data) between modules written in C and those in C+ + (with C interface). Is there a standard body which has described what constitutes valid/invalid behaviour in this regard -and a test suite that helps me ensure that I am adhering to the reqd standard? thanks -kamal ...

fortran to c
somebody pls tell me -- is there any tool available to convert FORTRAN source code to C or C++ somebody pls tell me -- is there any tool available to convert FORTRAN source code to C or C++ somebody pls tell me -- is there any tool available to convert FORTRAN source code to C or C++ somebody pls tell me -- is there any tool available to convert FORTRAN source code to C or C++ On 9 Jun 2006 14:13:49 -0700, indiandude staggered into the Black Sun and said: > Somebody please tell me -- is there any tool available to convert > FORTRAN source code to C or C++? [snip] Don't post the sa...

C to Fortran?
I've seen several posts here recently apparently made by people used to C/C++ who are novices at Fortran. I don't know if this is a general trend? Could it be that people doing technical programming are slowly realising that C isn't really a very good language for the job, and (even more unlikely) maybe there is something of a resurgence of interest in Fortran? What I don't know is whether there are any good texts/tutorials to help them? I suspect it may be necessary to spend as much effort un-learning the features of C as learning those of Fortran. Maybe ...

Include C/C++ compiled file in a Fortran project (Windows)
Hi, I need to include a C/C++ file (compiled) in my Fortran project. I use MS Visual Studio (Compaq Visual Fortran and MS Visual C++) and must create a DLL file of my Fortran project. I have a thought that it would be possible to include my C/C++ file as an 'obj' file (include this object file as a 'Resuource file' in the project). Is this correct? Anyone who can give me some help on how I create an object file from my C/C++ file? Many thanks, MM MM wrote: | Hi, | | I need to include a C/C++ file (compiled) in my Fortran project. I use MS | Visual Studio (Compaq Vi...

Fortran and C++
hi, how can i use existing library in Fortran for my C++ program. I have try f2c but it is rather cubersome... Can I compile the Fortran code into Object file and then link to C++ code? My thanks TF To Forum wrote: > How can I use existing library in Fortran for my C++ program. > I have try f2c but it is rather cubersome. > Can I compile the Fortran code into Object file and then link to C++ code? Yes. But the details depend upon your target platform. platform = machine architecture, operating system, C++ compiler and Fortran compiler. On Sat, 10 Jul 2004 01:51:01 +0200, "...

interfacing matlab/simulink to routines written in c/c++/fortran
I am working on a project that involves interfacing three different routines together that are written in Matlab/Simulink, Fortran90, c++. The Matlab/Simulink program is the driver and it must be able to effectively communicate with the other two programs (It must have bi-directional communication that is as fast as possible). I would prefer not to use MEX technology. Does anyone know what the best approach would be to accomplish this task? Ken Yetzer wrote: > I am working on a project that involves interfacing three different > routines together that are written in Matlab/Simulink, Fo...

how to call C (non-intel C compiler) from ifort (intel fortran)?
Hi there, I need to call C within fortran code. I could compile and link using Visual Fortran and Visual C++. Fortran code is like: .. CALL SUB1(arg1, .......) .. .. C code is like: #define sub1 __stdcall SUB1 .. void sub1 ( arg1, ........) .. .. Now I have to use another machine with Intel Fortran (ifort) with .NET (Visual Studio 2005). When I linked, I got error message "unresolved external symbol _SUB1". What is the right way to do? (For using ifort with icc, an example is shown in http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/Intel64Cluster/Doc/fortrancallc.html) Any...

can we use const& non-const arguments in function overloading.
Hi Can we overload a function based on const & non-const arguments. e.g is it valid to have two functions with prototype as ..... 1) void ask(int i); 2) void ask(const int i); [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] ashwani wrote: > Hi > Can we overload a function based on const & non-const arguments. > > e.g > is it valid to have two functions with prototype as ..... > > 1) void ask(int i); > 2) void ask(const int i); No. These declare the same function. If y...

Cannot convert 'const void *' to 'const char *' in C++
Hi, I am using a API I downloaded from the internet programmed in C. I need the function below which works with this api in my c++ file - void StoreNoteCallback(void *context, int arglen, const void *args, OSCTimeTag when, NetworkReturnAddressPtr returnAddr) { const char *typeArgs = (const char *)args; const float *floatArgs = &typeArgs[OSCPaddedStrlen(args)]; } The problem is that the gives me the errors - Cannot convert 'const void *' to 'const char *' in function StoreNoteCallback Type mismatch in parameter 's' (wanted 'const char *', got ...

floating point programming: c/c++ vs matlab vs fortran vs ???
Dear all, I am helping someone code a model of an optical amplifier in C code (with the aim of verifying results published by someone else). The model seems to behave correctly for a limited range of parameters, but is quite off outside this range. This is unacceptable; AFAICT theres no algorithmic reason the model should fail, so I suspect things are going wrong in floating point land. As I've been reading up on the matter I find there is a lot that could be going wrong: floating point exceptions, rounding errors etc. The model can be run reasonably quick, so we'd happily sacrifice ...