diff --git a/lec08/hello.c b/lec08/hello.c new file mode 100644 index 0000000000000000000000000000000000000000..a118c5d093ecabe1a78b7d0768b7dfeb7dcd6e2b --- /dev/null +++ b/lec08/hello.c @@ -0,0 +1,31 @@ +#include <stdio.h> + +int add(int *a, int *b, int *c) +{ + *c = *a + *b; +} + +int main() +{ + int a = 100; + int b = 200; + int c = 999; + // int * == long long + + fprintf(stdout, "%d : %lld %llx\n", a,(long long) &a,(long long) &a); + fprintf(stdout, "%d : %lld %llx\n", b, (long long)&b, (long long)&b); + add(&a, &b ,&c); + //c = a+b + fprintf(stdout, "%s %d : %d\n",__FILE__, __LINE__,c); + fprintf(stdout, "%s %d : %d\n",__FILE__, __LINE__,c); + fprintf(stdout, "%s %d : %d\n",__FILE__, __LINE__,c); +#define ERR_DATA 2000 +#if ERR_DATA > 1000 +#error 1024 +#else +#warning ERR_DATA +#endif + fprintf(stdout, "%s %d : %d",__FILE__, __LINE__,c); + + +} diff --git a/lec08/hello.o b/lec08/hello.o new file mode 100644 index 0000000000000000000000000000000000000000..fb73646a9b4f3fb332b497cd582ffb9c07749bec Binary files /dev/null and b/lec08/hello.o differ diff --git a/lec08/hello.s b/lec08/hello.s new file mode 100644 index 0000000000000000000000000000000000000000..8905c7658bde2b87a9a56498760e946ffb136619 --- /dev/null +++ b/lec08/hello.s @@ -0,0 +1 @@ + .file "hello.c" diff --git a/lec08/hellocpp.c b/lec08/hellocpp.c new file mode 100644 index 0000000000000000000000000000000000000000..62c47ba3da64ef885ff8d010c50f56813cc22163 --- /dev/null +++ b/lec08/hellocpp.c @@ -0,0 +1,30 @@ +# 1 "hello.c" +# 1 "<built-in>" +# 1 "<command-line>" +# 31 "<command-line>" +# 1 "/usr/include/stdc-predef.h" 1 3 4 +# 32 "<command-line>" 2 +# 1 "hello.c" + + +int add(int *a, int *b, int *c) +{ + *c = *a + *b; +} + +int main() +{ + const int a = 100; + int b = 200; + long long c = 999; + + + fprintf(stdout, "%d : %lld %llx\n", a, &a, &a); + fprintf(stdout, "%d : %lld %llx\n", b, &b, &b); + add(&a, &b ,&c); + + fprintf(stdout, "%d : %lld %llx\n", c, &c, &c); + fprintf(stdout, "%d : %lld %llx\n", c, &c+1, &c+1); + fprintf(stdout, "%d : %lld %llx\n", c, &c+2, &c+2); + +} diff --git a/lec08/hellocpp.o b/lec08/hellocpp.o new file mode 100644 index 0000000000000000000000000000000000000000..eaa376831f288714a2c00d1ab029a86dd97db229 Binary files /dev/null and b/lec08/hellocpp.o differ diff --git a/lec08/hellocpp.s b/lec08/hellocpp.s new file mode 100644 index 0000000000000000000000000000000000000000..6f73298bf2668685f42ac23d994e915e25ef337f --- /dev/null +++ b/lec08/hellocpp.s @@ -0,0 +1 @@ + .file "hellocpp.c" diff --git a/lec08/macrotest.c b/lec08/macrotest.c new file mode 100644 index 0000000000000000000000000000000000000000..39a86aff8260121dc13aae96a10136f404040fa2 --- /dev/null +++ b/lec08/macrotest.c @@ -0,0 +1,14 @@ +#define HE HI +#define LLO _THERE +#define HELLO "HI THERE" +#define CAT(a,b) a##b +#define XCAT(a,b) CAT(a,b) +#define CALL(fn) fn(HE,LLO) +CAT(HE,LLO) // "HI THERE", because concatenation occurs before normal expansion +XCAT(HE,LLO) // HI_THERE, because the tokens originating from parameters ("HE" and "LLO") are expanded first +CALL(CAT) // "HI THERE", because parameters are expanded first + +#define sq(a) a*a +sq(B) +#define sq(a) aaa +sq(C)