home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / forum7.lzh / RICO / C / LIBSOURCE / ARGPROC / varargs.h < prev   
Text File  |  2009-11-06  |  1KB  |  52 lines

  1.  
  2. /*    OS9 variable arguments passing functions,
  3.     recommended use:
  4.  
  5.     function(<known args>, va_alist)
  6.     <known args declarations>
  7.         va_dcl
  8.     {    <local var declarations>
  9.         va_list    va;
  10.  
  11.         va_start(&va);
  12.         <arg1> = va_arg(&va,<arg1 type>);
  13.         <arg2> = va_arg(&va,<arg2 type>);
  14.         ...
  15.         va_end(&va);
  16.         <rest of function>
  17.     }
  18.  
  19.     Any arguments of integral type (integers, pointers ...) and
  20.     doubles are accessible.    */
  21.  
  22.  
  23.  
  24. /*    item - basic argument type passed on the stack    */
  25. typedef    unsigned long int    item;
  26.  
  27. /*    va_list - information necessary to access arguments */
  28. typedef    struct {    short int num, cont1, cont2;
  29.                     item *next, *arg1, *args; }    va_list;
  30.  
  31. /*    OS9 Microware C passes the first 2 arguments in registers,
  32.     so we have to handle them separately    */
  33. #define    va_alist                _arg0_,_arg1_,_args_
  34. #define    va_dcl                    item _arg0_,_arg1_,_args_;
  35.  
  36. /*    necessary(type) - how many items are necessary for type ?    */
  37. #define    necessary(type)            ((sizeof(type)+sizeof(item)-1)/sizeof(item))
  38. #define    _LITTLE_                necessary(item)
  39. #define    _BIG_                    (_LITTLE_+_LITTLE_)
  40.  
  41. /*    va_start(va) - initialize va to the first argument    */
  42. /*    if _arg0_,_arg1_ and _args_ have subsequent adresses,
  43.     no special handling is necessary    */
  44. #define    va_start(va)            _va_init(va,&_arg0_,&_arg1_,&_args_)
  45.  
  46. /*    va_arg(va,type) - get next argument of type    */
  47. #define va_arg(va,type)    *(type *)_va_get(va,necessary(type))
  48.  
  49. /*    va_end(va) - end of argument parsing    */
  50. #define    va_end(va)
  51.  
  52.