OSDN Git Service

2006-12-03 Paul Thomas <pault@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gfortran.dg / value_4.c
1 /*  Passing from fortran to C by value, using VALUE.  This is identical
2     to c_by_val_1.c, which performs the same function for %VAL.
3
4     Contributed by Paul Thomas <pault@gcc.gnu.org>  */
5
6 typedef struct { float r, i; } complex;
7 extern float *f_to_f__ (float, float*);
8 extern int *i_to_i__ (int, int*);
9 extern void c_to_c__ (complex*, complex, complex*);
10 extern void abort (void);
11
12 /* In f_to_f and i_to_i we return the second argument, so that we do
13    not have to worry about keeping track of memory allocation between
14    fortran and C.  All three functions check that the argument passed
15    by value is the same as that passed by reference.  Then the passed
16    by value argument is modified so that the caller can check that
17    its version has not changed.*/
18
19 float *
20 f_to_f__(float a1, float *a2)
21 {
22   if ( a1 != *a2 ) abort();
23   *a2 = a1 * 2.0;
24   a1 = 0.0;
25   return a2;
26 }
27
28 int *
29 i_to_i__(int i1, int *i2)
30 {
31   if ( i1 != *i2 ) abort();
32   *i2 = i1 * 3;
33   i1 = 0;
34   return i2;
35 }
36
37 void
38 c_to_c__(complex *retval, complex c1, complex *c2)
39 {
40   if ( c1.r != c2->r ) abort();
41   if ( c1.i != c2->i ) abort();
42   c1.r = 0.0;
43   c1.i = 0.0;
44   retval->r = c2->r * 4.0;
45   retval->i = c2->i * 4.0;
46   return;
47 }
48