aboutsummaryrefslogtreecommitdiff
path: root/tests/tests2/94_generic.c
diff options
context:
space:
mode:
authorMatthias Gatto <uso.cosmo.ray@gmail.com>2017-07-05 16:46:20 +0200
committerMatthias Gatto <uso.cosmo.ray@gmail.com>2017-07-05 17:59:42 +0200
commit16d3dbf2d087c92810d8d8354822a5345978e32c (patch)
treec724b732539ca7765f2d0b72883caf264686278e /tests/tests2/94_generic.c
parent157bad52cdb052015f64a29e47099b2470f67c3e (diff)
downloadtinycc-16d3dbf2d087c92810d8d8354822a5345978e32c.tar.gz
tinycc-16d3dbf2d087c92810d8d8354822a5345978e32c.tar.bz2
add _Generic test
Diffstat (limited to 'tests/tests2/94_generic.c')
-rw-r--r--tests/tests2/94_generic.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/tests2/94_generic.c b/tests/tests2/94_generic.c
new file mode 100644
index 0000000..fad028b
--- /dev/null
+++ b/tests/tests2/94_generic.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+
+const int a = 0;
+
+struct a {
+ int a;
+};
+
+struct b {
+ int a;
+};
+
+int a_f()
+{
+ return 20;
+}
+
+int b_f()
+{
+ return 10;
+}
+
+#define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123);
+
+int main()
+{
+ int i = 0;
+ struct b titi;
+ const int * const ptr;
+ const char *ti;
+
+ i = _Generic(a, int: a_f, const int: b_f)();
+ printf("%d\n", i);
+ i = _Generic(ptr, int *:1, int * const:2, default:20);
+ printf("%d\n", i);
+ i = gen_sw(a);
+ printf("%d\n", i);
+ i = _Generic(titi, struct a:1, struct b:2, default:20);
+ printf("%d\n", i);
+ i = _Generic(a, char:1, int[4]:2, default:5);
+ printf("%d\n", i);
+ i = _Generic(17, int :1, int **:2);
+ printf("%d\n", i);
+ i = _Generic(17L, int :1, long :2);
+ printf("%d\n", i);
+ i = _Generic("17, io", const char *:1, char *:3, const int :2);
+ printf("%d\n", i);
+ i = _Generic(ti, const char *:1, char *:3, const int :2);
+ printf("%d\n", i);
+ return 0;
+}