Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,45 @@
module c_api
use iso_c_binding
implicit none
interface
function strdup(ptr) bind(C)
import c_ptr
type(c_ptr), value :: ptr
type(c_ptr) :: strdup
end function
end interface
interface
subroutine free(ptr) bind(C)
import c_ptr
type(c_ptr), value :: ptr
end subroutine
end interface
interface
function puts(ptr) bind(C)
import c_ptr, c_int
type(c_ptr), value :: ptr
integer(c_int) :: puts
end function
end interface
end module
program c_example
use c_api
implicit none
character(20), target :: str = "Hello, World!" // c_null_char
type(c_ptr) :: ptr
integer(c_int) :: res
ptr = strdup(c_loc(str))
res = puts(c_loc(str))
res = puts(ptr)
print *, transfer(c_loc(str), 0_c_intptr_t), &
transfer(ptr, 0_c_intptr_t)
call free(ptr)
end program