View previous topic :: View next topic |
Author |
Message |
dbradly
Joined: 20 Nov 2006 Posts: 31
|
Posted: Fri Jan 12, 2007 12:07 pm Post subject: Passing array elements in .NET |
|
|
I have upgraded to FTN95 v5.01 in order to build our libraries compatible for VS2005. I am therefore using /clr /clr_ver 2 and dbk_link2.
I have code that passes a .NET structure array to a Fortran array and in my existing code I did this by passing an array reference arr(1).
In v5.01 I now get an error: *** Elements of .NET arrays cannot be passed as arguments.
If I remove the (1) I get the error: *** In the INTERFACE to PERCN3 (from MODULE SURF_F77), the 14th dummy argument (WW) was of type REAL(KIND=2), whereas the actual argument is of type OBJECT('System.Double[]')
How do I pass a reference to a .NET array to Fortran? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Fri Jan 12, 2007 7:11 pm Post subject: |
|
|
This restriction has been added to FTN95 because of the problem of .NET garbage collection. If garbage collection occurs whilst the routine is running then the array will probably be moved and the reference to it will nolonger be valid.
Previously the code may have worked (particularly if there was no IO involved) but it will have been unsafe. Any IO is likely to trigger garbage collection. |
|
Back to top |
|
|
dbradly
Joined: 20 Nov 2006 Posts: 31
|
Posted: Mon Jan 15, 2007 10:30 am Post subject: |
|
|
Does this mean I cannot pass a .NET array reference to Fortran, or is there an alternative method? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Tue Jan 16, 2007 10:07 pm Post subject: |
|
|
Yes it does mean this. You could use /IGNORE <n> for this error but the code will be unsafe.
Basically you should not pass back (by reference) anything that the .NET garbage collector might move whilst you are in the routine. Fortran has no way of knowing that the .NET object may have moved and needs to be written back to a different address. FTN95 tries to prevent you from doing this. |
|
Back to top |
|
|
|