Re: is it possible to pass C++ vectors to fortran subroutines



glen herrmannsfeldt wrote:
Louis Krupp wrote:
utab wrote:

I don't know if this is portable (even if it works), but you might try:

compute_(a.front(), b.front(), c.front(), &sz);

That would be my guess, too. .front() is supposed to return a
pointer to the first element of the <vector>, which should work
like a C pointer.

front() returns either std::vector::const_reference or std::vector::reference. Neither of these can be passed to a pointer argument. That's why you have to take the address of front() to get this to work.

The 2007 draft of the stanard containts a std::vector::data() member that will return a pointer.


When Fortran 2003 C interoperability is in good shape, you might
be able to make a Fortran defined type to match <vector>.

Do you mean a Fortran defined type that would have the same functionality as std::vector? That's certain possible.

Or do you mean something that could be used to allow code like this c++ snippet?

....
std::vector<int> a;
FORTRANSUB(&a); // calls a Fortran subroutine
....

I foresee all kinds of problems with that.

LR



.



Relevant Pages

  • Re: Fortran article in Wikipedia
    ... > as those developed by others, which was especially true of FORTRAN ... compiler diagnostics compared to Fortran H although neither did the ... WatFor first appeared on IBM 7040s where the undefined variable ... > pointer causes an exception to be raised. ...
    (comp.lang.fortran)
  • Re: Calling C from FORTRAN
    ... This as a preparation for communication with regular Fortran object ... I stripped the ISO_C_BINDINGS use clauses from the interfacing Module ... POINTER, INTENT:: src, dst ... In the headerfile projPJ is introduced as follows (i.e. ...
    (comp.lang.fortran)
  • Re: Fortran and .NET (C#)
    ... pointer is destroyed, just like Fortran ALLOCATABLE. ... > return the address of the first element when returning an array. ...
    (comp.lang.fortran)
  • Re: Fortran based MEX w/ COMMON/SAVE
    ... I believe dat (pointer to the array) and the ... SAVE at the begining of each subroutine is a bit unusual to me. ... > to unload it if there isn't a Fortran END or STOP statement. ... interaction w/ Matlab). ...
    (comp.soft-sys.matlab)
  • Re: Down-cast a polymorphic pointer?
    ... which just translate calls from Fortran to class methods. ... class, pointer:: ch ... type:: cbase ... and the subroutine GetAnObject is better implemented in Fortran ...
    (comp.lang.fortran)