From: patrick@spellingbeewinnars.org
Subject: Very Excited About GnuCOBOL and Ada :)
Date: Fri, 19 Oct 2018 05:08:22 -0700 (PDT)
Date: 2018-10-19T05:08:22-07:00 [thread overview]
Message-ID: <8ca9b14d-e62d-4645-8b20-50bdb8ad7935@googlegroups.com> (raw)
Hi Everyone
I just wanted to share something I am excited about. I have been mixing GnuCOBOL and Ada for some time but the process was not a lot of fun.
I have had more luck this week. Here is what I did. I took Gnat.ByteSwapping and renamed it so that I would not accidentally end up using the one installed in my /usr/xxx directory.
I was able to use it without really writing any Ada code. I just had to modify the spec file a little bit. Here is the code:
Commands to build->
gcc -c gnat_byteswap.adb
gnatbind -n gnat_byteswap.ali
gcc -c b~gnat_byteswap.adb
cobc -x experiment.cob gnat_byteswap.o b~gnat_byteswap.o -lgnat
Altered Part Of Spec file:
procedure Swap2 (Location : System.Address);
pragma export(C, Swap2, "swap2") ;
procedure Swap4 (Location : System.Address);
pragma export(C, Swap4, "swap4") ;
procedure Swap8 (Location : System.Address);
pragma export(C, Swap8, "swap8") ;
The Body is unchanged.
Here is the GnuCOBOL program:
>>> source format is free
identification division.
program-id. "experiment" .
data division.
working-storage section.
01 2bytes pic x(2) value is "AB" .
01 4bytes pic x(4) value is "ABCD" .
01 8bytes pic x(8) value is "ABCDEFGH" .
procedure division .
call "adainit" end-call
call "swap2" using by reference 2bytes
end-call
call "swap4" using by reference 4bytes
end-call
call "swap8" using by reference 8bytes
end-call
display 2bytes
display 4bytes
display 8bytes
goback .
end program "experiment" .
GnuCOBOL support many code styles, this is just mine and not representative.
Notice that I used pragma export(C... ) and not COBOL. I am not confident in Ada's current support of COBOL. I am going to investigate this further and I hope to add missing functionality such as support for pointers and functions found in GnuCOBOL.
It's really exciting to simply take Ada library code, alter it just a bit with pragma export and then be able to use it in GnuCOBOL. I don't know Fortran as well but I am going to also try to do the same thing with gfortran. I am going to share this with the GnuCOBOL community soon and then eventually the gfortran one too. The same process could also bring Ada libraries to C and C++ users with minimal fuss. Code changes could just come in the form of patches.
reply other threads:[~2018-10-19 12:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox