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



.