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.



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. ...
  • 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. ...
  • Re: "null Considered Harmful"
    ... or test time, but they always creep though, and few ... Those were a NULL pointer are involved are he relatively ... The traditional (Fortran 66 days) libraries were ...
  • Re: Fortran and .NET (C#)
    ... pointer is destroyed, just like Fortran ALLOCATABLE. ... > return the address of the first element when returning an array. ...
  • Re: Callback Procedure Assist
    ... !unsigned short *pBuf - pointer to the first of an array of WORD samples ... !unsigned long Context - a copy of the Context parameter to pass in) ... You need the name specifier if you a) want the binding label of the subroutine to be different from the default (which I think is an all lower case variant of the Fortran name) or b) you can never confidently remember what the default is so you'd prefer to be explicit about the binding label in your source. ... I get very confused where aspects of that declaration potentially come from entities declared or use associated within the scope of the function itself - hence I prefer to use a result clause and function type declaration inside the body of the function. ...