Debian Codegraph @

gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c

raw
1 /* Test the fix for PR92123. */
2
3 /* Contributed by Vipul Parekh <[email protected]> */
4
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <ISO_Fortran_binding.h>
8
9 // Prototype for Fortran functions
10 extern void Fsub(CFI_cdesc_t *);
11
12 int main()
13 {
14 /* Note: ISO C forbids zero-size array 'dim' [-Wpedantic]
15 Therefore, even though 'dat' represents a scalar, it is set rank 1/ */
16 CFI_CDESC_T(1) dat;
17 int irc = 0;
18
19 irc = CFI_establish((CFI_cdesc_t *)&dat, NULL,
20 CFI_attribute_allocatable,
21 CFI_type_int, 0, (CFI_rank_t)0, NULL);
22 if (irc != CFI_SUCCESS)
23 {
24 printf("CFI_establish failed: irc = %d.\n", irc);
25 return EXIT_FAILURE;
26 }
27
28 Fsub((CFI_cdesc_t *)&dat);
29 if (*(int *)dat.base_addr != 42)
30 {
31 printf("Fsub returned = %d.\n", *(int *)dat.base_addr);
32 return EXIT_FAILURE;
33 }
34
35 irc = CFI_deallocate((CFI_cdesc_t *)&dat);
36 if (irc != CFI_SUCCESS)
37 {
38 printf("CFI_deallocate for dat failed: irc = %d.\n", irc);
39 return EXIT_FAILURE;
40 }
41
42 return EXIT_SUCCESS;
43 }