This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: ICE on valid
On Saturday, September 22, 2012 07:15:44 PM Janus Weil wrote:
> Hi,
>
> > Thanks for confirming, and for figuring out that this is actually invalid
> > code. In this case my goal was just to pass a pointer to a Fortran
> > polymorphic variable through to the C-side of my code, and then be able
> > to pass that pointer back later on.
>
> if you do that, then I guess you have to convert your Fortran
> polymorphic pointer to a C_PTR at some point, probably via C_LOC,
> right? However, C_LOC should not accept polymorphic arguments in the
> first place. Haven't you been bitten by this?
I haven't tried working around this yet, but my idea was to wrap the
polymorphic object in a derived type:
type :: wrapperType
class(ncb), pointer :: polyObject
endtype wrapperType
and then actually pass a pointer to a (non-polymorphic) wrapperType object to
C. Once passed back to Fortran I could then access the polymorphic object
inside the wrapper. (In the code from which my test case originated the
polymorphic pointers are actually already contained inside another derived
type, so this doesn't require much change.)
I haven't tried this though, so perhaps there's some reason why it won't work.
Cheers,
Andrew.
--
* Andrew Benson: http://users.obs.carnegiescience.edu/abenson/contact.html
* Galacticus: http://sites.google.com/site/galacticusmodel