modernc.org/ccgo/v3@v3.16.14/lib/testdata/gcc-9.1.0/gcc/testsuite/gcc.c-torture/execute/va-arg-24.c (about)

     1  /* The purpose of this code is to test argument passing of a tuple of
     2     11 integers, with the break point between named and unnamed arguments
     3     at every possible position.	*/
     4  
     5  #include <stdarg.h>
     6  #include <stdio.h>
     7  #include <stdlib.h>
     8  
     9  static int errors = 0;
    10  
    11  static void
    12  verify (const char *tcase, int n[11])
    13  {
    14    int i;
    15    for (i = 0; i <= 10; i++)
    16      if (n[i] != i)
    17        {
    18  	printf (" %s: n[%d] = %d expected %d\n", tcase, i, n[i], i);
    19  	errors++;
    20        }
    21  }
    22  
    23  #define STR(x) #x
    24  
    25  #define p(i) int q##i,
    26  #define P(i) n[i] = q##i;
    27  
    28  #define p0 p(0)
    29  #define p1 p(1)
    30  #define p2 p(2)
    31  #define p3 p(3)
    32  #define p4 p(4)
    33  #define p5 p(5)
    34  #define p6 p(6)
    35  #define p7 p(7)
    36  #define p8 p(8)
    37  #define p9 p(9)
    38  
    39  #define P0 P(0)
    40  #define P1 P(1)
    41  #define P2 P(2)
    42  #define P3 P(3)
    43  #define P4 P(4)
    44  #define P5 P(5)
    45  #define P6 P(6)
    46  #define P7 P(7)
    47  #define P8 P(8)
    48  #define P9 P(9)
    49  
    50  #define TCASE(x, params, vecinit)		\
    51  static void					\
    52  varargs##x (params ...)				\
    53  {						\
    54    va_list ap;					\
    55    int n[11];					\
    56    int i;					\
    57  						\
    58    va_start (ap, q##x);				\
    59    vecinit					\
    60    for (i = x + 1; i <= 10; i++)			\
    61      n[i] = va_arg (ap, int);			\
    62    va_end (ap);					\
    63  						\
    64    verify (STR(varargs##x), n);			\
    65  }
    66  
    67  #define TEST(x) varargs##x (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    68  
    69  TCASE(0, p0			      , P0			     )
    70  TCASE(1, p0 p1			      , P0 P1			     )
    71  TCASE(2, p0 p1 p2		      , P0 P1 P2		     )
    72  TCASE(3, p0 p1 p2 p3		      , P0 P1 P2 P3		     )
    73  TCASE(4, p0 p1 p2 p3 p4		      , P0 P1 P2 P3 P4		     )
    74  TCASE(5, p0 p1 p2 p3 p4 p5	      , P0 P1 P2 P3 P4 P5	     )
    75  TCASE(6, p0 p1 p2 p3 p4 p5 p6	      , P0 P1 P2 P3 P4 P5 P6	     )
    76  TCASE(7, p0 p1 p2 p3 p4 p5 p6 p7      , P0 P1 P2 P3 P4 P5 P6 P7	     )
    77  TCASE(8, p0 p1 p2 p3 p4 p5 p6 p7 p8   , P0 P1 P2 P3 P4 P5 P6 P7 P8   )
    78  TCASE(9, p0 p1 p2 p3 p4 p5 p6 p7 p8 p9, P0 P1 P2 P3 P4 P5 P6 P7 P8 P9)
    79  
    80  int main(void)
    81  {
    82    TEST(0);
    83    TEST(1);
    84    TEST(2);
    85    TEST(3);
    86    TEST(4);
    87    TEST(5);
    88    TEST(6);
    89    TEST(7);
    90    TEST(8);
    91    TEST(9);
    92  
    93    if (errors)
    94      abort ();
    95    exit (0);
    96  }