[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / BlocksRuntime / variadic.c
blob1d80657e98867fbb6a0027998f5fe3a9e42c0294
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
7 /*
8 * variadic.c
9 * testObjects
11 * Created by Blaine Garst on 2/17/09.
15 // PURPOSE Test that variadic arguments compile and work for Blocks
16 // CONFIG
18 #include <stdarg.h>
19 #include <stdio.h>
21 int main(int argc, char *argv[]) {
23 long (^addthem)(const char *, ...) = ^long (const char *format, ...){
24 va_list argp;
25 const char *p;
26 int i;
27 char c;
28 double d;
29 long result = 0;
30 va_start(argp, format);
31 //printf("starting...\n");
32 for (p = format; *p; p++) switch (*p) {
33 case 'i':
34 i = va_arg(argp, int);
35 //printf("i: %d\n", i);
36 result += i;
37 break;
38 case 'd':
39 d = va_arg(argp, double);
40 //printf("d: %g\n", d);
41 result += (int)d;
42 break;
43 case 'c':
44 c = va_arg(argp, int);
45 //printf("c: '%c'\n", c);
46 result += c;
47 break;
49 //printf("...done\n\n");
50 return result;
52 long testresult = addthem("ii", 10, 20);
53 if (testresult != 30) {
54 printf("got wrong result: %ld\n", testresult);
55 return 1;
57 testresult = addthem("idc", 30, 40.0, 'a');
58 if (testresult != (70+'a')) {
59 printf("got different wrong result: %ld\n", testresult);
60 return 1;
62 printf("%s: Success\n", argv[0]);
63 return 0;