comp.lang.ada
 help / color / mirror / Atom feed
* Very Excited About GnuCOBOL and Ada :)
@ 2018-10-19 12:08 patrick
  0 siblings, 0 replies; only message in thread
From: patrick @ 2018-10-19 12:08 UTC (permalink / 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.



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-10-19 12:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-19 12:08 Very Excited About GnuCOBOL and Ada :) patrick

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox