1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LLVM_LICENSE_HEADER@
5 */
6
7/*
8 *  variadic.c
9 *  testObjects
10 *
11 *  Created by Blaine Garst on 2/17/09.
12 *  Copyright 2009 Apple. All rights reserved.
13 *
14 */
15
16// PURPOSE Test that variadic arguments compile and work for Blocks
17// TEST_CONFIG
18
19#import <stdarg.h>
20#import <stdio.h>
21#import "test.h"
22
23int main() {
24
25    long (^addthem)(const char *, ...) = ^long (const char *format, ...){
26        va_list argp;
27        const char *p;
28        int i;
29        char c;
30        double d;
31        long result = 0;
32        va_start(argp, format);
33        //printf("starting...\n");
34        for (p = format; *p; p++) switch (*p) {
35            case 'i':
36                i = va_arg(argp, int);
37                //printf("i: %d\n", i);
38                result += i;
39                break;
40            case 'd':
41                d = va_arg(argp, double);
42                //printf("d: %g\n", d);
43                result += (int)d;
44                break;
45            case 'c':
46                c = va_arg(argp, int);
47                //printf("c: '%c'\n", c);
48                result += c;
49                break;
50        }
51        //printf("...done\n\n");
52        return result;
53    };
54    long testresult = addthem("ii", 10, 20);
55    if (testresult != 30) {
56        fail("got wrong result: %ld", testresult);
57    }
58    testresult = addthem("idc", 30, 40.0, 'a');
59    if (testresult != (70+'a')) {
60        fail("got different wrong result: %ld", testresult);
61    }
62
63    succeed(__FILE__);
64}
65
66
67