- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everybody,
I have problems when tryng to compile the GTK-Fortran interface defined by Jerry Delisle and Vincent Magnin (see https://gitub.com/jerryd/gtk-fortran) with ifort 12.1.4 on Fedora fc16.
The problems come from all the Fortran functions that should return a c_ptr pointer and use it before leaving the function : the pointer returned by the function has a wrong value . The result are ok with gfortran.
As it is too difficult to look inside the GTK-Fortran interface I have reproduced the problem in a small test program (see attached files)
Here is an example of the function which cause problem :
[bash]!! A high-level function which : !! - call def_point to define the pointer point !! - call set_value in order to put ival in the location pointed by point !! This high-level function define the pointer and use it before exiting function hl_def_point(ival) result(point) use mymod use iso_c_binding, only: c_ptr,c_int implicit none integer(c_int),intent(in)::ival type(c_ptr)::point integer(c_int)::ier ! *****define the pointer point point=def_point() ! *****we use the pointer point before exiting ier=set_value(point,ival) end function hl_def_point[/bash] Curiously the problem can be overcome by definig and using a local c_ptr pointer and defining the function value only at the end just before leaving the function :
[bash]!! A high-level function which : !! - call def_point to define the pointer point !! - call set_value in order to put ival in the location pointed by point !! This high-level function defines a local pointer, uses it, and !! defines the resulting pointer only just before exiting function hl_def_point(ival) result(point) use mymod use iso_c_binding, only: c_ptr,c_int implicit none integer(c_int),intent(in)::ival type(c_ptr)::mypoint,point integer(c_int)::ier ! *****define the pointer mypoint mypoint=def_point() ! *****we use the pointer mypoint before exiting ier=set_value(mypoint,ival) point=mypoint end function hl_def_point[/bash] However I don't really understand why this trick works !
This looks like a rather subtle bug about c_ptr
I have problems when tryng to compile the GTK-Fortran interface defined by Jerry Delisle and Vincent Magnin (see https://gitub.com/jerryd/gtk-fortran) with ifort 12.1.4 on Fedora fc16.
The problems come from all the Fortran functions that should return a c_ptr pointer and use it before leaving the function : the pointer returned by the function has a wrong value . The result are ok with gfortran.
As it is too difficult to look inside the GTK-Fortran interface I have reproduced the problem in a small test program (see attached files)
Here is an example of the function which cause problem :
[bash]!! A high-level function which : !! - call def_point to define the pointer point !! - call set_value in order to put ival in the location pointed by point !! This high-level function define the pointer and use it before exiting function hl_def_point(ival) result(point) use mymod use iso_c_binding, only: c_ptr,c_int implicit none integer(c_int),intent(in)::ival type(c_ptr)::point integer(c_int)::ier ! *****define the pointer point point=def_point() ! *****we use the pointer point before exiting ier=set_value(point,ival) end function hl_def_point[/bash] Curiously the problem can be overcome by definig and using a local c_ptr pointer and defining the function value only at the end just before leaving the function :
[bash]!! A high-level function which : !! - call def_point to define the pointer point !! - call set_value in order to put ival in the location pointed by point !! This high-level function defines a local pointer, uses it, and !! defines the resulting pointer only just before exiting function hl_def_point(ival) result(point) use mymod use iso_c_binding, only: c_ptr,c_int implicit none integer(c_int),intent(in)::ival type(c_ptr)::mypoint,point integer(c_int)::ier ! *****define the pointer mypoint mypoint=def_point() ! *****we use the pointer mypoint before exiting ier=set_value(mypoint,ival) point=mypoint end function hl_def_point[/bash] However I don't really understand why this trick works !
This looks like a rather subtle bug about c_ptr
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am fairly certain that this is our issue ID DPD200179339 in which the compiler does not properly pass by value nor receive as function return values consisting of a "small" structure when the called routine is declared as BIND(C). This is fixed for a release later this year. I need to verify this.
A workaround might be to declare the return type as an INTGER(C_INTPTR_T) and use TRANSFER to convert it to a C_PTR.
A workaround might be to declare the return type as an INTGER(C_INTPTR_T) and use TRANSFER to convert it to a C_PTR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Steve,
For the time being I prefer to use my trick of defining a local c_ptr pointer inside the function because it avoids to change the type of the the function and to search all the locations where it is called. The Gtk-Fortran interface is a rather big stuff which involves many functions of this kind !
Is it possible to see somewhere the list and the definition of the current issues like ID DPD2001179339 ?
Hope that the new release will come soon
Many thanks for your help
talziary
For the time being I prefer to use my trick of defining a local c_ptr pointer inside the function because it avoids to change the type of the the function and to search all the locations where it is called. The Gtk-Fortran interface is a rather big stuff which involves many functions of this kind !
Is it possible to see somewhere the list and the definition of the current issues like ID DPD2001179339 ?
Hope that the new release will come soon
Many thanks for your help
talziary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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