diff --git a/test/misc/Makefile b/test/misc/Makefile index 898ea1b2b..96f61dba1 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -78,6 +78,11 @@ $(WORKDIR)/bug760.$1.$2.prg: bug760.c | $(WORKDIR) $(if $(QUIET),echo misc/bug760.$1.$2.prg) -$(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) +# should compile, but gives an error +$(WORKDIR)/pptest2.$1.$2.prg: pptest2.c | $(WORKDIR) + $(if $(QUIET),echo misc/pptest2.$1.$2.prg) + -$(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + # this should fail to compile, because cc65 does not support returning structs $(WORKDIR)/bug264.$1.$2.prg: bug264.c | $(WORKDIR) $(if $(QUIET),echo misc/bug264.$1.$2.prg) diff --git a/test/misc/pptest2.c b/test/misc/pptest2.c new file mode 100644 index 000000000..7857c67b2 --- /dev/null +++ b/test/misc/pptest2.c @@ -0,0 +1,73 @@ + +/* preprocessor test #2 */ + +#include +#include +#include + +int y = 7; +int z[] = {1, 2, 3}; +int res; + +int f(int i) { + printf("f: %d\n", i); + return i + 1; +} +int t(int i) { + printf("t: %d\n", i); + return i + 1; +} +int m(int i, int j) { + printf("m: %d %d\n", i, j); + return i + j + 1; +} + +#define x 3 +#define f(a) f(x * (a)) +#undef x +#define x 2 +#define g f +#define z z[0] +#define h g(~ +#define m(a) a(w) +#define w 0,1 +#define t(a) a +#define p() int +#define q(x) x +#define r(x,y) x ## y +#define str(x) # x + +int main(void) +{ + res = f(y+1) + f(f(z)) % t(t(g) (0) + t)(1); + printf("res: %d expected: 19\n", res); + if (res != 19) { + return EXIT_FAILURE; + } + + res = g(x+(3,4)-w) | h 5) & m(f)^m(m); + printf("res: %d expected: 3\n", res); + if (res != 3) { + return EXIT_FAILURE; + } + + p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) }; + printf("i[]: %d %d %d %d\n", i[0], i[1], i[2], i[3]); + printf("expected: %d %d %d %d\n", 1, 23, 4, 5); + if ((i[0] != 1) || (i[1] != 23) || (i[2] != 4) || (i[3] != 5)) { + return EXIT_FAILURE; + } + + char c[2][6] = { str(hello), str() }; + printf ("c[0]: %s expected: %s\n", c[0], "hello"); + printf ("c[1]: %s expected: %s\n", c[1], ""); + if (strcmp(c[0], "hello") != 0) { + return EXIT_FAILURE; + } + if (strcmp(c[1], "") != 0) { + return EXIT_FAILURE; + } + + printf("all fine\n"); + return EXIT_SUCCESS; +} diff --git a/testcode/compiler/pptest2.c b/testcode/compiler/pptest2.c deleted file mode 100644 index e127d53fb..000000000 --- a/testcode/compiler/pptest2.c +++ /dev/null @@ -1,19 +0,0 @@ -#define x 3 -#define f(a) f(x * (a)) -#undef x -#define x 2 -#define g f -#define z z[0] -#define h g(~ -#define m(a) a(w) -#define w 0,1 -#define t(a) a -#define p() int -#define q(x) x -#define r(x,y) x ## y -#define str(x) # x - -f(y+1) + f(f(z)) % t(t(g) (0) + t)(1); -g(x+(3,4)-w) | h 5) & m(f)^m(m); -p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) }; -char c[2][6] = { str(hello), str() };