home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-2.LHA / CLISP960530-ki.lha / ffcall / vacall / vacall.man < prev    next >
Encoding:
Text File  |  1996-04-15  |  10.9 KB  |  265 lines

  1.  
  2.  
  3.  
  4. VACALL(3)                                               VACALL(3)
  5.  
  6.  
  7. NNAAMMEE
  8.        vacall - C functions called with variable arguments
  9.  
  10. SSYYNNOOPPSSIISS
  11.        ##iinncclluuddee <<vvaaccaallll..hh>>
  12.  
  13.        eexxtteerrnn vvooiidd** vvaaccaallll__ffuunnccttiioonn;;
  14.  
  15.        vvooiidd _f_u_n_c_t_i_o_n ((_a_l_i_s_t))
  16.          vvaa__aalliisstt _a_l_i_s_t;;
  17.        {{
  18.          vvaa__ssttaarrtt___t_y_p_e((_a_l_i_s_t[[,, _r_e_t_u_r_n___t_y_p_e]]));;
  19.          _a_r_g == vvaa__aarrgg___t_y_p_e((_a_l_i_s_t[[,, _a_r_g___t_y_p_e]]));;
  20.          vvaa__rreettuurrnn___t_y_p_e((_a_l_i_s_t[[[[,, _r_e_t_u_r_n___t_y_p_e]],, _r_e_t_u_r_n___v_a_l_u_e]]));;
  21.        }}
  22.  
  23.        vvaaccaallll__ffuunnccttiioonn == _&_f_u_n_c_t_i_o_n;;
  24.  
  25.        _v_a_l == ((((_r_e_t_u_r_n___t_y_p_e ((**)) (()))) vvaaccaallll)) ((_a_r_g_1,,_a_r_g_2,,_._._.));;
  26.  
  27. DDEESSCCRRIIPPTTIIOONN
  28.        This  set  of  macros  permit  a C function _f_u_n_c_t_i_o_n to be
  29.        called with variable  arguments  and  to  return  variable
  30.        return values.  This is much like the vvaarraarrggss(3) facility,
  31.        but also allows the return value to be  specified  at  run
  32.        time.
  33.  
  34.        Function  calling  conventions differ considerably on dif-
  35.        ferent machines,  and  _v_a_c_a_l_l  attempts  to  provide  some
  36.        degree of isolation from such architecture dependencies.
  37.  
  38.        The  function  that can be called with any number and type
  39.        of arguments and which will  return  any  type  of  return
  40.        value is vvaaccaallll.  It will do some magic and call the func-
  41.        tion stored in the variable vvaaccaallll__ffuunnccttiioonn.  If you  want
  42.        to make more than one use of _v_a_c_a_l_l, use the _t_r_a_m_p_o_l_i_n_e(3)
  43.        facility to  store  _&_f_u_n_c_t_i_o_n  into  vvaaccaallll__ffuunnccttiioonn  just
  44.        before calling vvaaccaallll.
  45.  
  46.        Within  _f_u_n_c_t_i_o_n, the following macros can be used to walk
  47.        through the argument list and specify a return value:
  48.  
  49.        vvaa__ssttaarrtt___t_y_p_e((_a_l_i_s_t[[,, _r_e_t_u_r_n___t_y_p_e]]));;
  50.               starts the walk through the argument list and spec-
  51.               ifies the return type.
  52.  
  53.        _a_r_g == vvaa__aarrgg___t_y_p_e((_a_l_i_s_t[[,, _a_r_g___t_y_p_e]]));;
  54.               fetches the next argument from the argument list.
  55.  
  56.        vvaa__rreettuurrnn___t_y_p_e((_a_l_i_s_t[[[[,, _r_e_t_u_r_n___t_y_p_e]],, _r_e_t_u_r_n___v_a_l_u_e]]));;
  57.               ends  the walk through the argument list and speci-
  58.               fies the return value.
  59.  
  60.        The _t_y_p_e in vvaa__ssttaarrtt___t_y_p_e and vvaa__rreettuurrnn___t_y_p_e shall be  one
  61.  
  62.  
  63.  
  64.                           10 March 1995                         1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. VACALL(3)                                               VACALL(3)
  71.  
  72.  
  73.        of  vvooiidd,  iinntt,  uuiinntt, lloonngg, uulloonngg, ddoouubbllee, ssttrruucctt, ppttrr or
  74.        (for ANSI C calling conventions only) cchhaarr, sscchhaarr,  uucchhaarr,
  75.        sshhoorrtt,   uusshhoorrtt,   ffllooaatt,   depending   on  the  class  of
  76.        _r_e_t_u_r_n___t_y_p_e.
  77.  
  78.        The _t_y_p_e specifiers in  vvaa__ssttaarrtt___t_y_p_e  and  vvaa__rreettuurrnn___t_y_p_e
  79.        must  be  the  same.  The _r_e_t_u_r_n___t_y_p_e specifiers passed to
  80.        vvaa__ssttaarrtt___t_y_p_e and vvaa__rreettuurrnn___t_y_p_e must be the same.
  81.  
  82.        The _t_y_p_e in vvaa__aarrgg___t_y_p_e shall be one of iinntt,  uuiinntt,  lloonngg,
  83.        uulloonngg,  ddoouubbllee, ssttrruucctt, ppttrr or (for ANSI C calling conven-
  84.        tions only) cchhaarr,  sscchhaarr,  uucchhaarr,  sshhoorrtt,  uusshhoorrtt,  ffllooaatt,
  85.        depending on the class of _a_r_g___t_y_p_e.
  86.  
  87.        In  vvaa__ssttaarrtt__ssttrruucctt((_a_l_i_s_t,,  _r_e_t_u_r_n___t_y_p_e,,  _s_p_l_i_t_t_a_b_l_e));; the
  88.        _s_p_l_i_t_t_a_b_l_e flag specifies whether the  struct  _r_e_t_u_r_n___t_y_p_e
  89.        can  be returned in registers such that every struct field
  90.        fits entirely in a single register. This needs to be spec-
  91.        ified  for  structs of size 2*sizeof(long). For structs of
  92.        size <= sizeof(long), _s_p_l_i_t_t_a_b_l_e is ignored and assumed to
  93.        be  1. For structs of size > 2*sizeof(long), _s_p_l_i_t_t_a_b_l_e is
  94.        ignored and assumed to be 0. There are some  handy  macros
  95.        for this:
  96.        vvaa__wwoorrdd__sspplliittttaabbllee__11 ((_t_y_p_e_1))
  97.        vvaa__wwoorrdd__sspplliittttaabbllee__22 ((_t_y_p_e_1,, _t_y_p_e_2))
  98.        vvaa__wwoorrdd__sspplliittttaabbllee__33 ((_t_y_p_e_1,, _t_y_p_e_2,, _t_y_p_e_3))
  99.        vvaa__wwoorrdd__sspplliittttaabbllee__44 ((_t_y_p_e_1,, _t_y_p_e_2,, _t_y_p_e_3,, _t_y_p_e_4))
  100.        For a struct with three slots
  101.        ssttrruucctt {{ _t_y_p_e_1 _i_d_1;; _t_y_p_e_2 _i_d_2;; _t_y_p_e_3 _i_d_3;; }}
  102.        you can specify _s_p_l_i_t_t_a_b_l_e as vvaa__wwoorrdd__sspplliittttaabbllee__33 ((_t_y_p_e_1,,
  103.        _t_y_p_e_2,, _t_y_p_e_3)) .
  104.  
  105.  
  106. NNOOTTEESS
  107.        Functions which want to emulate Kernighan & Ritchie  style
  108.        functions  (i.e.,  in  ANSI  C,  functions without a typed
  109.        argument list) cannot use the  _t_y_p_e  values  cchhaarr,  sscchhaarr,
  110.        uucchhaarr, sshhoorrtt, uusshhoorrtt, ffllooaatt.  As prescribed by the default
  111.        K&R C expression promotions, they have to use iinntt  instead
  112.        of cchhaarr, sscchhaarr, uucchhaarr, sshhoorrtt, uusshhoorrtt and ddoouubbllee instead of
  113.        ffllooaatt.
  114.  
  115.  
  116. EEXXAAMMPPLLEE
  117.        This example, a possible implementation of eexxeeccll(3) on top
  118.        of eexxeeccvv(2) using vvaarraarrggss(3),
  119.  
  120.        ##iinncclluuddee <<vvaarraarrggss..hh>>
  121.        ##ddeeffiinnee MMAAXXAARRGGSS 110000
  122.        //** eexxeeccll iiss ccaalllleedd bbyy eexxeeccll((ffiillee,, aarrgg11,, aarrgg22,, ......,, ((cchhaarr **))00));; **//
  123.        iinntt eexxeeccll ((vvaa__aalliisstt))
  124.          vvaa__ddccll
  125.        {{
  126.          vvaa__lliisstt aapp;;
  127.  
  128.  
  129.  
  130.                           10 March 1995                         2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. VACALL(3)                                               VACALL(3)
  137.  
  138.  
  139.          cchhaarr** ffiillee;;
  140.          cchhaarr** aarrggss[[MMAAXXAARRGGSS]];;
  141.          iinntt aarrggnnoo == 00;;
  142.          vvaa__ssttaarrtt ((aapp));;
  143.          ffiillee == vvaa__aarrgg((aapp,, cchhaarr**));;
  144.          wwhhiillee ((((aarrggss[[aarrggnnoo]] == vvaa__aarrgg((aapp,, cchhaarr**)))) !!== ((cchhaarr **))00))
  145.            aarrggnnoo++++;;
  146.          vvaa__eenndd ((aapp));;
  147.          rreettuurrnn eexxeeccvv((ffiillee,, aarrggss));;
  148.        }}
  149.  
  150.        looks like this using vvaaccaallll(3):
  151.  
  152.        ##iinncclluuddee <<vvaaccaallll..hh>>
  153.        ##ddeeffiinnee MMAAXXAARRGGSS 110000
  154.        //** eexxeeccll iiss ccaalllleedd bbyy vvaaccaallll((ffiillee,, aarrgg11,, aarrgg22,, ......,, ((cchhaarr **))00));; **//
  155.        vvooiidd eexxeeccll ((aapp))
  156.          vvaa__aalliisstt aapp;;
  157.        {{
  158.          cchhaarr** ffiillee;;
  159.          cchhaarr** aarrggss[[MMAAXXAARRGGSS]];;
  160.          iinntt aarrggnnoo == 00;;
  161.          iinntt rreettvvaall;;
  162.          vvaa__ssttaarrtt__iinntt ((aapp));;
  163.          ffiillee == vvaa__aarrgg__ppttrr((aapp,, cchhaarr**));;
  164.          wwhhiillee ((((aarrggss[[aarrggnnoo]] == vvaa__aarrgg__ppttrr((aapp,, cchhaarr**)))) !!== ((cchhaarr **))00))
  165.            aarrggnnoo++++;;
  166.          rreettvvaall == eexxeeccvv((ffiillee,, aarrggss));;
  167.          vvaa__rreettuurrnn__iinntt ((aapp,, rreettvvaall));;
  168.        }}
  169.        vvaaccaallll__ffuunnccttiioonn == &&eexxeeccll;;
  170.  
  171.  
  172. SSEEEE AALLSSOO
  173.        vvaarraarrggss(3), ttrraammppoolliinnee(3).
  174.  
  175.  
  176. BBUUGGSS
  177.        The  current  implementations have been tested on a selec-
  178.        tion of common cases but there  are  probably  still  many
  179.        bugs.
  180.  
  181.        There  are  typically  built-in  limits on the size of the
  182.        argument-list, which may also  include  the  size  of  any
  183.        structure arguments.
  184.  
  185.        The  decision whether a struct is to be returned in regis-
  186.        ters or in memory considers only  the  struct's  size  and
  187.        alignment.  This  is inaccurate: for example, gcc on m68k-
  188.        next returns ssttrruucctt {{  cchhaarr  aa,,bb,,cc;;  }}  in  registers  and
  189.        ssttrruucctt  {{ cchhaarr aa[[33]];; }} in memory, although both types have
  190.        the same size and the same alignment.
  191.  
  192.        <<vvaaccaallll..hh>>  cannot  be  included   when   <<vvaarraarrggss..hh>>   or
  193.  
  194.  
  195.  
  196.                           10 March 1995                         3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. VACALL(3)                                               VACALL(3)
  203.  
  204.  
  205.        <<ssttddaarrgg..hh>> is included.  (Name clash for vvaa__aalliisstt.)
  206.  
  207.        The argument list can only be walked once.
  208.  
  209.  
  210. PPOORRTTIINNGG
  211.        Knowledge  about argument passing conventions can be found
  212.        in the gcc source, file  gcc-2.6.3/config/_c_p_u/_c_p_u.h,  sec-
  213.        tion "Stack layout; function entry, exit and calling."
  214.  
  215.        The  implementation of varargs for gcc can be found in the
  216.        gcc source, files gcc-2.6.3/ginclude/va*.h.
  217.  
  218.        gcc's __builtin_saveregs() function is defined in the  gcc
  219.        source, file gcc-2.6.3/libgcc2.c.
  220.  
  221.  
  222. AAUUTTHHOORR
  223.        Bruno Haible <haible@ma2s2.mathematik.uni-karlsruhe.de>
  224.  
  225.  
  226. AACCKKNNOOWWLLEEDDGGEEMMEENNTTSS
  227.        Many  ideas  and  a  lot of code were cribbed from the gcc
  228.        source.
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.                           10 March 1995                         4
  263.  
  264.  
  265.