Files
acceptance-tests
data
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
cmake
docs
include
lib
test
BlocksRuntime
block-static.c
blockimport.c
byrefaccess.c
byrefcopy.c
byrefcopycopy.c
byrefcopyinner.c
byrefcopyint.c
byrefcopystack.c
byrefsanity.c
byrefstruct.c
c99.c
cast.c
constassign.c
copy-block-literal-rdar6439600.c
copyconstructor.C
copynull.c
dispatch_async.c
dispatch_call_Block_with_release.c
fail.c
flagsisa.c
globalexpression.c
goto.c
hasdescriptor.c
josh.C
k-and-r.c
large-struct.c
localisglobal.c
macro.c
makefile
modglobal.c
nestedimport.c
nullblockisa.c
objectRRGC.c
objectassign.c
orbars.c
rdar6396238.c
rdar6405500.c
rdar6414583.c
recursive-block.c
recursive-test.c
recursiveassign.c
reference.C
rettypepromotion.c
returnfunctionptr.c
shorthandexpression.c
sizeof.c
small-struct.c
structmember.c
testfilerunner.h
testfilerunner.m
varargs-bad-assign.c
varargs.c
variadic.c
voidarg.c
asan
builtins
cfi
dfsan
esan
fuzzer
hwasan
interception
lsan
msan
profile
safestack
sanitizer_common
scudo
tsan
ubsan
ubsan_minimal
xray
CMakeLists.txt
lit.common.cfg
lit.common.configured.in
unittests
www
.arcconfig
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
README.txt
eng
libcxx
libcxxabi
libunwind
lld
lldb
llvm
nuget
openmp
polly
Directory.Build.props
Directory.Build.targets
NuGet.config
azure-pipelines.yml
build.cmd
build.sh
dir.common.props
global.json
llvm.proj
mxe-Win64.cmake.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h

67 lines
1.6 KiB
C
Raw Normal View History

//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
/*
* variadic.c
* testObjects
*
* Created by Blaine Garst on 2/17/09.
*
*/
// PURPOSE Test that variadic arguments compile and work for Blocks
// CONFIG
#include <stdarg.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
long (^addthem)(const char *, ...) = ^long (const char *format, ...){
va_list argp;
const char *p;
int i;
char c;
double d;
long result = 0;
va_start(argp, format);
//printf("starting...\n");
for (p = format; *p; p++) switch (*p) {
case 'i':
i = va_arg(argp, int);
//printf("i: %d\n", i);
result += i;
break;
case 'd':
d = va_arg(argp, double);
//printf("d: %g\n", d);
result += (int)d;
break;
case 'c':
c = va_arg(argp, int);
//printf("c: '%c'\n", c);
result += c;
break;
}
//printf("...done\n\n");
return result;
};
long testresult = addthem("ii", 10, 20);
if (testresult != 30) {
printf("got wrong result: %ld\n", testresult);
return 1;
}
testresult = addthem("idc", 30, 40.0, 'a');
if (testresult != (70+'a')) {
printf("got different wrong result: %ld\n", testresult);
return 1;
}
printf("%s: Success\n", argv[0]);
return 0;
}