Skip to content

Commit a850b83

Browse files
committed
Fix runme for old function pointer test
1 parent 64817c7 commit a850b83

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

Examples/test-suite/fortran/funcptr_runme.F90

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,39 @@
22

33
#include "fassert.h"
44

5+
module funcptr_mod
6+
use, intrinsic :: ISO_C_BINDING
7+
implicit none
8+
contains
9+
10+
function myexp(left, right) bind(C) &
11+
result(fresult)
12+
use, intrinsic :: ISO_C_BINDING
13+
integer(C_INT), intent(in), value :: left
14+
integer(C_INT), intent(in), value :: right
15+
integer(C_INT) :: fresult
16+
17+
fresult = left ** right
18+
end function
19+
20+
end module
21+
522
program funcptr_runme
623
use funcptr
24+
use funcptr_mod
725
use ISO_C_BINDING
826
implicit none
9-
type(C_FUNPTR) :: fp
27+
procedure(SWIGTYPE_f_int_int__int), pointer :: fp
1028

11-
! Add
12-
call set_handle(0, fp)
29+
! Get the C++ function handle, which starts out as 'add'
30+
fp => get_funcvar()
31+
ASSERT(fp(2, 3) == 5)
1332
ASSERT(do_op(2, 3, fp) == 5)
1433

15-
! Subtract
16-
call set_handle(1, fp)
17-
call set_funcvar(fp)
18-
ASSERT(do_op(2, 3, get_funcvar()) == -1)
34+
! Set the function handle
35+
call set_funcvar(myexp)
36+
! Get it back, then call it from C++
37+
ASSERT(do_op(2, 3, get_funcvar()) == 8)
1938

2039
end program
2140

0 commit comments

Comments
 (0)