scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit e058f92b4049440893187d087de983c670d2348d
parent bc25f140c1c9d2c51f81e3d767dcc8ae532d662c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 23 Mar 2022 12:57:25 +0100

tests/cc: Add 0202-variadic.c

Diffstat:
Atests/cc/execute/0202-variadic.c | 44++++++++++++++++++++++++++++++++++++++++++++
Mtests/cc/execute/scc-tests.lst | 1+
2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/tests/cc/execute/0202-variadic.c b/tests/cc/execute/0202-variadic.c @@ -0,0 +1,44 @@ +#define debug1(...) test1(__VA_ARGS__) +#define debug2(...) test2(0, #__VA_ARGS__) +#define debug3(t, ...) ((t==1) ? test1(__VA_ARGS__):test2(__VA_ARGS__)) + +int +test1(int x, char *s) +{ + int i; + + if (x != 3) + return 0; + for (i = 0; s[i]; i++) { + if (s[i] != "test1"[i]) + return 0; + } + return 1; +} + +int +test2(int x, char *s) +{ + int i; + + for (i = 0; s[i]; i++) { + if (s[i] != "1, 2"[i]) + return 0; + } + return 1; +} + +int +main() +{ + if (!debug1(3, "test1")) + return 1; + if (!debug2(1, 2)) + return 2; + if (!debug3(1, 3, "test1")) + return 3; + if (!debug3(2, 0, "1, 2")) + return 4; + + return 0; +} diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst @@ -192,3 +192,4 @@ 0199-voidpcast.c [TODO] 0200-cpp.c [TODO] 0201-cpp.c [TODO] +0202-variadic.c [TODO]