/*$ -fno-inline $*/
+#include <stdio.h>
+
int val;
-#define T(name,OP) \
- int test_##name(void) { return val OP 7; } \
- int test2_##name(int v) { return val OP v; } \
- int testp_##name(void) { return 7 OP val; } \
- int testp2_##name(int v) { return v OP val; }
+#define TTYPE(name,type,OP) \
+ type test_##name##type(void) { return val OP 7; } \
+ type test2_##name##type(type v) { return val OP v; } \
+ type testp_##name##type(void) { return 7 OP val; } \
+ type testp2_##name##type(type v) { return v OP val; }
int test_cmp_testset(int v, int v2) { return (v & 14) > 0; }
+#define T(name,OP) \
+ TTYPE(name,int,OP) \
+ TTYPE(name,short,OP) \
+ TTYPE(name,char,OP)
+
T(add,+)
T(sub,-)
T(or,|)
T(shr,>>)
#undef T
+#undef TTYPE
int main(void) {
int res1, res2, res3, res4;
val = 11;
-#define T(name,OP) \
- res1 = test_##name(); \
- res2 = test2_##name(20); \
- res3 = testp_##name(); \
- res4 = testp2_##name(20); \
- printf("Test %s: %d (should be %d)\n", #name, res1, 11 OP 7); \
- printf("Test2 %s: %d (should be %d)\n", #name, res2, 11 OP 20); \
- printf("Testp %s: %d (should be %d)\n", #name, res3, 7 OP 11); \
- printf("Testp2 %s: %d (should be %d)\n", #name, res4, 20 OP 11);
+#define TTYPE(name,type,OP) \
+ res1 = test_##name##type(); \
+ res2 = test2_##name##type(20); \
+ res3 = testp_##name##type(); \
+ res4 = testp2_##name##type(20); \
+ printf("Test %s: %d (should be %d)\n", #name, res1, (type) 11 OP (type) 7); \
+ printf("Test2 %s: %d (should be %d)\n", #name, res2, (type) 11 OP (type)20); \
+ printf("Testp %s: %d (should be %d)\n", #name, res3, (type) 7 OP (type)11); \
+ printf("Testp2 %s: %d (should be %d)\n", #name, res4, (type) 20 OP (type)11);
+
+#define T(name,OP) \
+ TTYPE(name,int,OP) \
+ TTYPE(name,short,OP) \
+ TTYPE(name,char,OP)
T(add,+)
T(sub,-)
+#include <stdio.h>
+
char c;
int f(int x, int y) {
return p[k];
}
-#define T(name, OP, OP2) \
-void dest_am_##name(int *arr, int from, int to) { \
+#define TTYPE(name, type, OP, OP2) \
+void dest_am_##name##type(type *arr, int from, int to) { \
int i; \
\
for(i = from; i < to; ++i) { \
} \
}
+#define T(name, OP, OP2) \
+ TTYPE(name,int,OP,OP2) \
+ TTYPE(name,short,OP,OP2) \
+ TTYPE(name,char,OP,OP2)
+
T(neg, -,)
T(not, ~,)
T(add, 3 +,)
T(shr, , >> 3)
int main(void) {
- int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ int arrint[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ short arrshort[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ char arrchar[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+
int i;
-#define C(name) dest_am_##name(arr, 0, 10); \
+#define CTYPE(type,name) dest_am_##name##type(arr##type, 0, 10); \
for(i = 0; i < 10; ++i) { \
- printf("%d ", arr[i]); \
+ printf("%d ", arr##type[i]); \
} \
printf("\n");
+#define C(name) \
+ CTYPE(int,name) \
+ CTYPE(short,name) \
+ CTYPE(char,name)
+
C(neg);
C(not);
C(add);