File: stdargx.h

package info (click to toggle)
xmlrpc-c 1.60.05-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,132 kB
  • sloc: ansic: 55,332; cpp: 13,541; sh: 3,321; makefile: 2,556; perl: 593; xml: 134
file content (67 lines) | stat: -rw-r--r-- 2,003 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef STDARGX_H_INCLUDED
#define STDARGX_H_INCLUDED

#include "xmlrpc_config.h"
#include <stdarg.h>
#include <string.h>

/*----------------------------------------------------------------------------
   We need a special version of va_list in order to pass around the
   variable argument heap by reference, thus allowing a subroutine to
   advance the heap's pointer.

   On some systems (e.g. Gcc for PPC or AMD64), va_list is an array.
   That invites the scourge of array-to-pointer degeneration if you try
   to take its address.  Burying it inside a struct as we do with our
   va_listx type makes it immune.

   Example of what would happen if we used va_list instead of va_listx,
   on a system where va_list is an array:

      void sub2(va_list * argsP) [
          ...
      }

      void sub1(va_list args) {
          sub2(&args);
      }

      This doesn't work.  '&args' is the same thing as 'args', so is
      va_list, not va_list *.  The compiler will even warn you about the
      pointer type mismatch.

  To use va_listx:

      void sub1_va(char * format, va_list args) {
          va_listx argsx;
          init_va_listx(&argsx, args);
          sub2(format, &argsx);
      }

-----------------------------------------------------------------------------*/


typedef struct {
/*----------------------------------------------------------------------------
   Same thing as va_list, but in a form that works everywhere.  See above.
-----------------------------------------------------------------------------*/
    va_list v;
} va_listx;



static __inline__ void
init_va_listx(va_listx * const argsxP,
              va_list    const args) {
#if VA_LIST_IS_ARRAY
    /* 'args' is NOT a va_list.  It is a pointer to the first element of a
       'va_list', which is the same address as a pointer to the va_list
       itself.  (That's what happens when you pass an array in C).
    */
    memcpy(&argsxP->v, args, sizeof(argsxP->v));
#else
    argsxP->v = args;
#endif
}

#endif