- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is an error in function c_loc in iso_c_binding module.
For ifort 2011.5.220,
nullify(fi)
a = c_loc(fi(1))
does not return a NULL toc. It works fine on ifort 11.0.081
Test files are attached
For ifort 2011.5.220,
nullify(fi)
a = c_loc(fi(1))
does not return a NULL toc. It works fine on ifort 11.0.081
Test files are attached
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your program is not legal. Quoting the standard, in its description of the argument to C_LOC: "If it is a pointer, it shall be associated". It is also not legal to reference fi(1) when fi is disassociated. The result of running this program is undefined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank. Now I got it. I changed all C_LOC calls in my code from
a = C_LOC(fi(1)
to
if (associated(fi)) then
a = C_LOC(fi(1))
else
a = C_NULL_PTR
endif
Then, it works fiine.
In my real code, the "nullify"s and "allocate"s are done somewhere else then C_LOC. So, I have to add the if statement to check if the fortran pointer is associated. In this sense, It would be easier to program if C_LOC can convert null fortran pointer to NULL C pointer although it is not the standard.
Thanks again.
Dong Zheng
a = C_LOC(fi(1)
to
if (associated(fi)) then
a = C_LOC(fi(1))
else
a = C_NULL_PTR
endif
Then, it works fiine.
In my real code, the "nullify"s and "allocate"s are done somewhere else then C_LOC. So, I have to add the if statement to check if the fortran pointer is associated. In this sense, It would be easier to program if C_LOC can convert null fortran pointer to NULL C pointer although it is not the standard.
Thanks again.
Dong Zheng
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you said C_LOC(fi) you would probably get the result you want, though this is still not legal Fortran. But what you have written is better overall.
![](/skins/images/B7BA37F9CE4B52FF7CAE1FB0388839C8/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page