HEllo, 

Bob Dubner wrote on gcc@
> 
> Thus, the statement
> 
>       CALL "foo"
> 
> might be the equivalent, implemented in C, of
> 
>       extern <type> foo(...); //External reference
>       foo();
> 
> or
> 
>       static <type> foo(...); // Forward reference to a static
> function
>       foo();
> 
> At the point of the CALL, we don't know which it's going to be.
> 
> This is further complicated by COBOL being able to do something that C can't: 
> 
>       CALL call_me
> 
> If C could do it, it would look like this:
> 
>       char call_me[] = "foo";
>       call_me();      // I told you C can't do it.
> 


If you restrict the GCC compiler and the compiled program to run on a Linux (or
POSIX) operating system, the dlsym(3) function is doing that (on global
functions only): fetching a function pointer from the string name of that global
function.
https://man7.org/linux/man-pages/man3/dlsym.3.html
https://man7.org/linux/man-pages/man3/dlopen.3.html

(you might consider generating unique C identifiers with some random generator)

Of course, dlsym(3) is computationally costly, you may want to cache the result.

And Cobol GCC experts (I am not one) could of course consider either generating
code with libgccjit (it is now inside GCC) or perhaps use GNU lightning to
generate machine code.
https://www.gnu.org/software/lightning/

Experimentally dlopen can be used many thousands of times (and with enough RAM
perhaps hundred thousands of times). See
https://github.com/bstarynk/misc-basile/blob/master/manydl.c


Regards
-- 
Basile STARYNKEVITCH                            <bas...@starynkevitch.net>
8 rue de la Faïencerie                       http://starynkevitch.net/Basile/  
92340 Bourg-la-Reine                         https://github.com/bstarynk
France                                https://github.com/RefPerSys/RefPerSys

Reply via email to