Fortran function in C++

This is a discussion on Fortran function in C++ within the C++ Programming forums, part of the General Programming Boards category; Hi there, I have been given a fortran90 .dll, of which I want to call a function. Now I know ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    Fortran function in C++

    Hi there,

    I have been given a fortran90 .dll, of which I want to call a function. Now I know some things:

    - one should pass by pointer (or this is simply the signature, I forgot)
    - one should declare the function "extern"
    - one should add an '_' to the function name

    Now everything's ok, except for the characters. Apparently the fortran standard does not prescribe a pass-by-pointer for character arrays. Several variations exist, which make use of the fact that the size of a fortran string is hidden in the string itself.

    Could anyone share his/her experience on this? I'm thinking ofmy own string class with a conversion constructor.

    Thanks a lot!!

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,261
    As you say, the Fortran standards have a different notion of strings than does C/C++: when a Fortran string is passed to a function, the length of the string is also passed (and there is no null termination either, as in a C-style string).

    The mechanism of passing a string as a function or subroutine argument is compiler dependent: some Fortran compilers implicitly pass a second argument with the length. Other compilers represent a Fortran string using (effectively) a data structure that is passed by reference.

    The rules of pass by pointer to an extern function, and adorning the function name with underscores is specific to your compiler. Other compilers can (and do) behave differently. In general you need to read the documentation for both your C/C++ compiler and the Fortran compiler to

    a) determine if the two compilers are even compatible (i.e. code from one can call a function from the other).

    b) determine what the mapping is for different types between compilers (adornment of function names, argument passing mechanisms, techniques for handling Fortran common blocks, etc etc).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21