summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/c_char_tests_5.f90
blob: c7a1c6e8c2bc4935104aa1288bbf671fb2dfb128 (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
! { dg-do run }
! { dg-options "-fbackslash" }
!
! PR fortran/103828
! Check that we can C char with non-ASCII values, which are interoperable
! with both INTEGER(C_SIGNED_CHAR) and CHARACTER(C_CHAR).

program test
  use, intrinsic :: iso_c_binding, only : c_signed_char, c_char
  implicit none

  interface
    ! In order to perform this test, we cheat and pretend to give each function
    ! the other one's prototype. It should still work, because all arguments
    ! are interoperable with C char.

    subroutine test1 (a) bind(c, name='test_int')
      import c_char
      character(kind=c_char, len=1), value :: a
    end subroutine test1

    subroutine test2 (a) bind(c, name='test_char')
      import c_signed_char
      integer(kind=c_signed_char), value :: a
    end subroutine test2

  end interface

  call test1('\xA3')
  call test2(-93_c_signed_char)

end program test

subroutine test_int (a) bind(c)
  use, intrinsic :: iso_c_binding, only : c_signed_char
  implicit none
  integer(c_signed_char), value :: a

  if (a /= iachar('\xA3', kind=c_signed_char)) stop 1
end subroutine

subroutine test_char (a) bind(c)
  use, intrinsic :: iso_c_binding, only : c_char
  implicit none
  character(kind=c_char, len=1), value :: a

  if (a /= '\xA3') stop 101
end subroutine