home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntinc25.zoo / varargs.h < prev    next >
C/C++ Source or Header  |  1992-12-12  |  2KB  |  83 lines

  1. #ifndef _VARARGS_H
  2. #define _VARARGS_H
  3.  
  4. #ifdef __TURBOC__
  5. #error varargs not implemented under Turbo C / Pure C
  6. #endif
  7.  
  8. /* in case stdarg.h got included by a header file */
  9. #ifdef va_start
  10. #undef va_start
  11. #undef va_end
  12. #undef va_dcl
  13. #undef va_alist
  14. #undef va_list
  15. #endif
  16.  
  17. #ifndef _COMPILER_H
  18. #include <compiler.h>
  19. #endif
  20.  
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24.  
  25. #ifndef __GNUC__
  26. /* I'm not sure this is right.  These apparently are all supposed to be
  27.    defines; doesn't seem to make much sense to make them functions.
  28.    There may be some missing from this list; these are the ones I found
  29.    by grepping around in code...
  30. */
  31.  
  32. /* a va_list is a list of random frobules */
  33. typedef __VA_LIST__ va_list;
  34.  
  35. /* the address of the list??? don't we already have that???  C programmers
  36.    pick the wierdest times to start worrying about abstractions! */
  37. #define va_start(args) args = (va_list) &va_alist
  38.  
  39. /* is this supposed to do anything??? */
  40. #define va_end(args)
  41.  
  42. /* This is apparently a general purpose accessor, used for storing, as 
  43.    well as snarfing.  This is the only way I could think of to make it
  44.    work that way.  Please, somebody, re-write this! */
  45. #define va_arg(args, elt_type) ((elt_type * ) ((args) += sizeof(elt_type)))[-1]
  46.  
  47. #define va_dcl    int va_alist;
  48.  
  49. #else
  50.  
  51. /* These macros implement traditional (non-ANSI) varargs
  52.    for GNU C.  */
  53. #if __GNUC__ > 1
  54. #define __va_ellipsis ...
  55. #else
  56. #define __va_ellipsis
  57. #endif
  58.  
  59. #define va_alist  __builtin_va_alist
  60. /* The ... causes current_function_varargs to be set in cc1.  */
  61. #define va_dcl    int __builtin_va_alist; __va_ellipsis
  62. #define va_list   __VA_LIST__
  63.  
  64. #define va_start(AP)  AP=(char *) &__builtin_va_alist
  65. #define va_end(AP)
  66.  
  67. #define __va_rounded_size(TYPE)  \
  68.   (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
  69.  
  70. #define va_arg(AP, TYPE)                                                \
  71.  (AP = (va_list) ((char *) (AP) + __va_rounded_size (TYPE)),    \
  72.  (sizeof(TYPE)<=sizeof(int)? ((TYPE *) (AP))[-1] :                       \
  73.   *((TYPE *) (void *) ((char *) (AP) - __va_rounded_size (TYPE)))))
  74.  
  75.  
  76. #endif /* __GNUC__ */
  77.  
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81.  
  82. #endif /* _VARARGS_H */
  83.