1.13. C functions

Felix can be forced to generate C/C++ style functions. The type:
  int * int --> int
with a long arrow denotes a C style function. The keywords cfun and cproc introduce such functions. C functions can be passed by value as in C, and are represented by the usual C function pointer.

C functions and procedures have no access to global variables or the garbage collector, and they use the system standard calling conventions for a C++ function.

Start felix section to tut/embedding/bind-1.12-0.flx[1 /1 ]
     1: #line 913 "./lpsrc/flx_tut_bind.pak"
     2: #import <flx.flxh>
     3: 
     4: cfun fff(x:int)=>x + 1;
     5: 
     6: print$ fff 22; endl;
     7: 
     8: fun apl(g:int-->int,x:int)=> g x;
     9: 
    10: print$ apl$ the fff,22; endl;
    11: 
    12: var q = the fff;
    13: print$ apl$ q,22; endl;
    14: 
    15: cproc ggg(x:int) {
    16:   print x; endl;
    17: }
    18: 
    19: ggg 42;
    20: 
    21: proc cll(g:int-->void, x:int) {
    22:   g x;
    23: }
    24: 
    25: cll$ the ggg, 43;
    26: 
    27: hhh := the ggg;
    28: 
    29: cll$ hhh, 44;
    30: 
    31: cfun f2(x:int, y:int)=>x+y;
    32: fun apl2(g:int*int-->int,x:int,y:int)=> g (x,y);
    33: print$ apl2$ the f2,12,13; endl;
    34: 
    35: cproc g2(x:int,y:int) {
    36:   print x; print " "; print y; endl;
    37: }
    38: 
    39: g2 (37,38);
    40: 
    41: proc cll2(g:int*int-->void,x:int,y:int) {
    42:   g (x,y);
    43: }
    44: 
    45: cll2(the g2, 39,40);
End felix section to tut/embedding/bind-1.12-0.flx[1]
Start data section to tut/embedding/bind-1.12-0.expect[1 /1 ]
     1: 23
     2: 23
     3: 23
     4: 42
     5: 43
     6: 44
     7: 25
     8: 37 38
     9: 39 40
End data section to tut/embedding/bind-1.12-0.expect[1]