home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / cecko / install / devcpp4920.exe / include / stdarg.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-17  |  2.9 KB  |  113 lines

  1. /*
  2.  * stdarg.h
  3.  *
  4.  * Provides facilities for stepping through a list of function arguments of
  5.  * an unknown number and type.
  6.  *
  7.  * NOTE: Gcc should provide stdarg.h, and I believe their version will work
  8.  *       with crtdll. If necessary I think you can replace this with the GCC
  9.  *       stdarg.h.
  10.  *
  11.  * Note that the type used in va_arg is supposed to match the actual type
  12.  * *after default promotions*. Thus, va_arg (..., short) is not valid.
  13.  *
  14.  * This file is part of the Mingw32 package.
  15.  *
  16.  * Contributors:
  17.  *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
  18.  *
  19.  *  THIS SOFTWARE IS NOT COPYRIGHTED
  20.  *
  21.  *  This source code is offered for use in the public domain. You may
  22.  *  use, modify or distribute it freely.
  23.  *
  24.  *  This code is distributed in the hope that it will be useful but
  25.  *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  26.  *  DISCLAMED. This includes but is not limited to warranties of
  27.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  28.  *
  29.  * $Revision: 1.5 $
  30.  * $Author: cgf $
  31.  * $Date: 2000/02/05 04:04:57 $
  32.  *
  33.  */
  34.  
  35. #ifndef _STDARG_H_
  36. #define _STDARG_H_
  37.  
  38. /* All the headers include this file. */
  39. #include <_mingw.h>
  40.  
  41. /*
  42.  * Don't do any of this stuff for the resource compiler.
  43.  */
  44. #ifndef RC_INVOKED
  45.  
  46. /* 
  47.  * I was told that Win NT likes this.
  48.  */
  49. #ifndef _VA_LIST_DEFINED
  50. #define _VA_LIST_DEFINED
  51. #endif
  52.  
  53. #ifndef    _VA_LIST
  54. #define _VA_LIST
  55. #if defined __GNUC__ && __GNUC__ >= 3
  56. typedef __builtin_va_list va_list;
  57. #else
  58. typedef char* va_list;
  59. #endif
  60. #endif
  61.  
  62. /*
  63.  * Amount of space required in an argument list (ie. the stack) for an
  64.  * argument of type t.
  65.  */
  66. #define __va_argsiz(t)    \
  67.     (((sizeof(t) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
  68.  
  69.  
  70. /*
  71.  * Start variable argument list processing by setting AP to point to the
  72.  * argument after pN.
  73.  */
  74. #ifdef    __GNUC__
  75. /*
  76.  * In GNU the stack is not necessarily arranged very neatly in order to
  77.  * pack shorts and such into a smaller argument list. Fortunately a
  78.  * neatly arranged version is available through the use of __builtin_next_arg.
  79.  */
  80. #define va_start(ap, pN)    \
  81.     ((ap) = ((va_list) __builtin_next_arg(pN)))
  82. #else
  83. /*
  84.  * For a simple minded compiler this should work (it works in GNU too for
  85.  * vararg lists that don't follow shorts and such).
  86.  */
  87. #define va_start(ap, pN)    \
  88.     ((ap) = ((va_list) (&pN) + __va_argsiz(pN)))
  89. #endif
  90.  
  91.  
  92. /*
  93.  * End processing of variable argument list. In this case we do nothing.
  94.  */
  95. #define va_end(ap)    ((void)0)
  96.  
  97.  
  98. /*
  99.  * Increment ap to the next argument in the list while returing a
  100.  * pointer to what ap pointed to first, which is of type t.
  101.  *
  102.  * We cast to void* and then to t* because this avoids a warning about
  103.  * increasing the alignment requirement.
  104.  */
  105.  
  106. #define va_arg(ap, t)                    \
  107.      (((ap) = (ap) + __va_argsiz(t)),        \
  108.       *((t*) (void*) ((ap) - __va_argsiz(t))))
  109.  
  110. #endif /* Not RC_INVOKED */
  111.  
  112. #endif /* not _STDARG_H_ */
  113.