C2F and function pointer arguments
Author Message
C2F and function pointer arguments

double qromo(double (*func)(double), double a, double b,
double (*choose)(double(*)(double), double, double))
{
double x;
x = (*choose)(func,a,b);
return x;

Quote:
}

Above C routine is part of test 86 in debug.c ..
Test 86 was inserted into debug.c from a stand-alone problem file
submitted by: Alexei Jiltsov

I then submitted the problem as usual to Jean Vezina,
who sent me back a manual translation, which I have implemented
in a C2F.ZIP uploaded today to:
ftp://members.aol.com/DaveGemini/TEST
which contains C2F.EXE   a C -> fortran95 translator (for win9x/NT)..

Dave

! --------------------------------------------------
FUNCTION qromo(I___func,a,b,I___choose)  RESULT (output_8)
! --------------------------------------------------
USE FUNCPOIN_1
IMPLICIT NONE
! - - - arg types - - -
REAL(8) :: output_8
REAL(8) :: a,b
! - - - local declarations - - -
POINTER (I___func, func)
POINTER (I___choose, choose)
REAL(8),EXTERNAL :: func,choose
REAL(8) :: x

! - - - begin - - -
x = choose(I___func,a,b)
output_8 = x
RETURN

END FUNCTION

Wed, 18 Jun 1902 08:00:00 GMT
C2F and function pointer arguments

Wed, 18 Jun 1902 08:00:00 GMT
C2F and function pointer arguments
Back in January,  "Count Dracula" submitted a {*filter*} C syntax
problem that C2F choked on...  (see below)...

--------------
typedef void *Pointer;

void swap(Pointer *a, Pointer *b)
{
Pointer tmp = *a;
*a = *b;
*b = tmp;

Quote:
}

int main (void)
{
struct S {char *name; int number;};
struct S s1, s2;
Pointer sp1, sp2;
s1.name = "name of 1";
s2.name = "name of 2";
s1.number =  200;
s2.number =  400;
sp1 = &s1;
sp2 = &s2;

swap(&sp1, &sp2);
printf("%s\n", ((struct S *)sp1)->name);
printf("%d\n", ((struct S *)sp1)->number);

return 0;

Quote:
}

C2F no longer chokes on above problem,
see below current translation...

! --------------------------------------------------
MODULE DRACULA_1         ! global declarations
! --------------------------------------------------
INCLUDE 'C2F.FD'
INCLUDE 'C2F.FI'
!  Pointer;

END MODULE

! --------------------------------------------------
SUBROUTINE swap(a,b)
! --------------------------------------------------
USE DRACULA_1
IMPLICIT NONE
! - - - arg types - - -
INTEGER :: a,b
! - - - local declarations - - -
INTEGER :: tmp

! - - - begin - - -
tmp = a
a = b
b = tmp

END SUBROUTINE

! --------------------------------------------------
PROGRAM DRACULA
! --------------------------------------------------
USE DRACULA_1
IMPLICIT NONE
! - - - local declarations - - -
INTEGER :: sp1,sp2
TYPE :: S
CHARACTER,POINTER :: name(:)
INTEGER :: number
END TYPE
POINTER (sp1, T_sp1)
TYPE (S) :: s1,s2,T_sp1

! - - - begin - - -
s1%name => .STRPTR."name of 1"
s2%name => .STRPTR."name of 2"
s1%number = 200
s2%number = 400
sp1 = LOC(s1)
sp2 = LOC(s2)
CALL swap(sp1, sp2)
WRITE (*,901) T_sp1%name
WRITE (*,902) T_sp1%number
STOP "0"

901 FORMAT (99A)
902 FORMAT (I0)
END PROGRAM
INCLUDE 'C2F_LIB.F90'
! Errors detected = 0  Warn:  0

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages