ugly but working

This commit is contained in:
tTh 2023-06-03 12:05:56 +02:00
parent 86553a65b5
commit f8d5e66a5c
6 changed files with 84 additions and 0 deletions

2
Call_the_C/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
call_the_c
*.o

20
Call_the_C/Makefile Normal file
View File

@ -0,0 +1,20 @@
#
# Fortran calls to a C function
#
all: call_the_c
# ----------------------------------------------------------
first-try.o: first-try.c Makefile
gcc -Wall -g -c $<
soundfiles.o: soundfiles.c Makefile
gcc -Wall -g -c $<
# ----------------------------------------------------------
call_the_c: call_the_c.f90 Makefile first-try.o
gfortran -Wall -g $< first-try.o -o $@
# ----------------------------------------------------------

12
Call_the_C/README.md Normal file
View File

@ -0,0 +1,12 @@
# Calling a C function
WARNING : THIS IS A WIP !
## Unix utilities
getpid, sleep, ...
## libsndfile
Bibliothèque de fonctions pour lire et écrire les fichiers sonores.

15
Call_the_C/call_the_c.f90 Normal file
View File

@ -0,0 +1,15 @@
program call_the_c
implicit none
integer :: foo
integer, external :: give_me_my_pid
print *, "XXX we are calling a C func"
call first_try ()
foo = give_me_my_pid()
print *, "process id = ", foo
print *, "XXX are we alive ?"
end program

24
Call_the_C/first-try.c Normal file
View File

@ -0,0 +1,24 @@
/*
* first try of a C func called from Fortran
*/
#include <stdio.h>
#include <unistd.h>
/* --------------------------------------------------------------- */
void first_try_(void)
{
fprintf(stderr, " pid=%u file='%s' func='%s' \n",
(long)getpid(), __FILE__, __func__);
}
/* --------------------------------------------------------------- */
long give_me_my_pid_ (void)
{
pid_t my_pid;
my_pid = (long)getpid();
fprintf(stderr, " %s -> %d\n", __func__, my_pid);
return my_pid;
}
/* --------------------------------------------------------------- */

11
Call_the_C/soundfiles.c Normal file
View File

@ -0,0 +1,11 @@
/*
* SOUNDFILES
* ----------
*
* Interface pour libsndfile
*/
#include <stdio.h>
/* --------------------------------------------------------------- */
/* --------------------------------------------------------------- */