This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, fortran] PR29642 - Fortran 2003: VALUE Attribute (pass by value)
- From: Paul Thomas <paulthomas2 at wanadoo dot fr>
- To: Fortran List <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 16 Nov 2006 18:47:21 +0100
- Subject: Re: [Patch, fortran] PR29642 - Fortran 2003: VALUE Attribute (pass by value)
- References: <45599379.4010206@wanadoo.fr> <45599680.9030400@wanadoo.fr>
I wrote:
On checking through this submission, as it arrived on the list, I
realised that there is another testcase that I will have to write,
that checks that an external C-procedure gets passed a value, if the
dummy in the interface has the value attribute. Please do not hold up
reviewing the patch for this, I will submit an additional patch
tonight or tomorrow.
Please find the testcase below.
Regards
Paul
_______________value_4.f90________________
! { dg-do run }
! { dg-additional-sources value_4.c }
! { dg-options "-ff2c -w -O0" }
!
! Tests the functionality of the patch for PR29642, which requested the
! implementation of the F2003 VALUE attribute for gfortran, by calling
! external C functions by value and by reference. This is effectively
! identical to c_by_val_1.f, which does the same for %VAL.
!
! Contributed by Paul Thomas <pault@gcc.gnu.org>
!
program value_4
interface
real function f_to_f (x, y)
real :: x, y
value :: x
end function f_to_f
end interface
interface
integer function i_to_i (x, y)
integer :: x, y
value :: x
end function i_to_i
end interface
interface
complex function c_to_c (x, y)
complex :: x, y
value :: x
end function c_to_c
end interface
real a, b, c
integer i, j, k
complex u, v, w
a = 42.0
b = 0.0
c = a
b = f_to_f (a, c)
if ((2.0 * a).ne.b) call abort ()
i = 99
j = 0
k = i
j = i_to_i (i, k)
if ((3 * i).ne.j) call abort ()
u = (-1.0, 2.0)
v = (1.0, -2.0)
w = u
v = c_to_c (u, w)
if ((4.0 * u).ne.v) call abort ()
end program value_4
_______________value_4.c________________
/* Passing from fortran to C by value, using VALUE. This is identical
to c_by_val_1.c, which performs the same function for %VAL. */
typedef struct { float r, i; } complex;
extern float f_to_f__ (float, float*);
extern long i_to_i__ (long, long*);
extern void c_to_c__ (complex*, complex, complex*);
extern void abort (void);
float
f_to_f__(float a1, float *a2)
{
if ( a1 != *a2 ) abort();
a1 = 0.0;
return *a2 * 2.0;
}
long
i_to_i__(long i1, long *i2)
{
if ( i1 != *i2 ) abort();
i1 = 0;
return *i2 * 3.0;
}
void
c_to_c__(complex *retval, complex c1, complex *c2)
{
if ( c1.r != c2->r ) abort();
if ( c1.i != c2->i ) abort();
c1.r = 0.0;
c1.i = 0.0;
retval->r = c2->r * 4.0;
retval->i = c2->i * 4.0;
return;
}