aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/c-interop/optional-c.c
blob: 9612d283486d8bf2d4e9763a9f3db29dfac52908 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdlib.h>
#include <stdio.h>

#include <ISO_Fortran_binding.h>
#include "dump-descriptors.h"

extern void ftest (int n, CFI_cdesc_t *a, int *b, char *c, double *d);
extern void ctest1 (CFI_cdesc_t *a, int *b, char *c, double *d);
extern void ctest2 (int n, CFI_cdesc_t *a, int *b, char *c, double *d);

static void *aa;
static int *bb;
static char *cc;
static double *dd; 

extern void
ctest1 (CFI_cdesc_t *a, int *b, char *c, double *d)
{
  /* Cache all the pointer arguments for later use by ctest2.  */
  aa = a->base_addr;
  bb = b;
  cc = c;
  dd = d;

  /* Test calling back into Fortran.  */
  ftest (0, NULL, NULL, NULL, NULL);
  ftest (1, a, NULL, NULL, NULL);
  ftest (2, a, b, NULL, NULL);
  ftest (3, a, b, c, NULL);
  ftest (4, a, b, c, d);
}

extern void
ctest2 (int n, CFI_cdesc_t *a, int *b, char *c, double *d)
{
  if (n >= 1)
    {
      if (!a)
	abort ();
      if (a->base_addr != aa)
	abort ();
    }
  else
    if (a)
      abort ();

  if (n >= 2)
    {
      if (!b)
	abort ();
      if (*b != *bb)
	abort ();
    }
  else
    if (b)
      abort ();

  if (n >= 3)
    {
      if (!c)
	abort ();
      if (*c != *cc)
	abort ();
    }
  else
    if (c)
      abort ();

  if (n >= 4)
    {
      if (!d)
	abort ();
      if (*d != *dd)
	abort ();
    }
  else
    if (d)
      abort ();

}