diff --git a/lec06/CallbyAddressAndCallbyValue.c b/lec06/CallbyAddressAndCallbyValue.c index 60edc780291595f4d68cd37c0a34fbdbc7cf0c6b..7a182110f8684a30f40e23543cb872fef9429e25 100644 --- a/lec06/CallbyAddressAndCallbyValue.c +++ b/lec06/CallbyAddressAndCallbyValue.c @@ -12,6 +12,9 @@ void addPointer(int *a, int *b, int *c) int addValue(int a, int b, int c) { + fprintf(stdout, "In addValue A %d : %lld %llx\n", a, &a, &a); + fprintf(stdout, "In addValue B %d : %lld %llx\n", b, &b, &b); + fprintf(stdout, "In addValue C %d : %lld %llx\n", c, &c, &c); c = a + b; fprintf(stdout, "In addValue A %d : %lld %llx\n", a, &a, &a); fprintf(stdout, "In addValue B %d : %lld %llx\n", b, &b, &b); diff --git a/lec07/debug. b/lec07/debug. new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/lec07/debug.c b/lec07/debug.c new file mode 100644 index 0000000000000000000000000000000000000000..02f9f376d6643eb5e217d99b2b9a0fafdce80482 --- /dev/null +++ b/lec07/debug.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#define DEBUG +#define INTRO + +int main() { +#ifdef DEBUG // #ifdef는 위에서 매크로가 선언된 경우 내부 코드가 실행됨 + printf("Debug : %s \t %s \t %s \t %d \n", __DATE__, __TIME__, __FILE__, __LINE__); +#endif + + char name[] = "Nayoung"; + int age = 21; + +#ifndef INTRO // #ifndef는 위에서 매크로가 선언되지 않은 경우 내부 코드를 실행함 + printf("Name : %s \t Age : %d \n", name, age); +#endif + return 0; +} diff --git a/lec07/debug_if.c b/lec07/debug_if.c new file mode 100644 index 0000000000000000000000000000000000000000..09b1cc9d772095ebe04e0134eacd08606d51bdad --- /dev/null +++ b/lec07/debug_if.c @@ -0,0 +1,11 @@ +#include <stdio.h> +#define DEBUG_LEVEL 2 + +int main() +{ +#if DEBUG_LEVEL >= 2 + printf("Debug Level 2 \n"); +#endif + + return 0; +} diff --git a/lec07/fnpointer.c b/lec07/fnpointer.c index aa57c07a1c65dc4621893d58edea1b8c4737720b..050ac5c5582844c3444ea0c5bb41d079bfcefbf7 100755 --- a/lec07/fnpointer.c +++ b/lec07/fnpointer.c @@ -3,6 +3,7 @@ #define FN_SUB 1 #define FN_MUL 2 #define FN_DIV 3 +#define FN_ERR 4 void add(int *a, int *b, int *c) { *c = *a + *b; } @@ -16,38 +17,43 @@ void mul(int *a, int *b, int *c) void div(int *a, int *b, int *c) { *c = (*a) / (*b); } +void err(int *a, int *b, int *c) +{ + *c = ' '; + fprintf(stdout, "wrong input\n"); +} + int main() { - int a, b, c; - char ch; - int op = FN_ADD; // default is add - - scanf("%d %c %d", &a, &ch, &b); - - void (*fp[4])(int *, int *, int *) = {add, sub, mul, div}; - switch (ch) - { - case '+': - op = FN_ADD; - break; - case '-': - op = FN_SUB; - break; - case '*': - op = FN_MUL; - break; - case '/': - op = FN_DIV; - break; - default : - op = FN_ADD; - break; + int a, b, c; + char ch; + int op = FN_ERR; // default is err + + scanf("%d %c %d", &a, &ch, &b); + + void (*fp[5])(int *, int *, int *) = {add, sub, mul, div, err}; + switch (ch) + { + case '+': + op = FN_ADD; + break; + case '-': + op = FN_SUB; + break; + case '*': + op = FN_MUL; + break; + case '/': + op = FN_DIV; + break; + default : + op = FN_ERR; + break; + } + + fp[op](&a,&b,&c); + if(op == 4){ + return 0; } - - fp[op](&a,&b,&c); fprintf(stdout, "%d \n", c); - - - // int const * p = &a; - // int * const q = &a; } diff --git a/lec07/func.c b/lec07/func.c index 5f18f12ccc955610c462367c75c8a57cf2118e96..9ea76a51273e590d52153bb3da53f95b6475876f 100644 --- a/lec07/func.c +++ b/lec07/func.c @@ -1,7 +1,5 @@ +#include "func.h" #define __FUNC_ 0 -#define FUNCTION_NEGATIVE -extern int fun1(int x); -extern int fun2(int x); #if __FUNC_ == 0 int func1(int a) @@ -21,4 +19,3 @@ int func3(int a) return DF(a+2)*20; } #endif - diff --git a/lec07/func.h.gch b/lec07/func.h.gch deleted file mode 100644 index 79be802fa6f687ab29fe2cac096143661e30e7c7..0000000000000000000000000000000000000000 Binary files a/lec07/func.h.gch and /dev/null differ diff --git a/lec07/main.c b/lec07/main.c index 359ed31407847bf46540e745cdf1a300d42076f4..4ceb2c1a733c7613395e89897bd2cbfd4ce391b0 100644 --- a/lec07/main.c +++ b/lec07/main.c @@ -1,7 +1,7 @@ #include <stdio.h> #define FUNCTION_NEGATIVE 1 #include "func.h" -#define __FUNC_ +#define __FUNC_ 0 int main() { printf("func1 %d %d\n", func1(100), DF(10));// func 110 100 @@ -9,4 +9,3 @@ int main() printf("func2 %d %d\n", func2(100), DF(10));// func 110 100 } - diff --git a/lec08/.string.c.swp b/lec08/.string.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..31bd9a708cc8db242a937817b44045227d8c72b4 Binary files /dev/null and b/lec08/.string.c.swp differ diff --git a/lec08/token.c b/lec08/token.c new file mode 100644 index 0000000000000000000000000000000000000000..a9670a44c65c1273c5b83c32fc0bb9d563bd45ea --- /dev/null +++ b/lec08/token.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#define DECLARE_STRUCT_TYPE(name) typedef struct name##_s name##_t + +int main(){ + + #define str(s) #s + printf("%s \n", str(1+2)); + + #define ST(a) #a + char name[] = ST(Nayoung); + printf("%s \n", name); + + DECLARE_STRUCT_TYPE(g_object); + + return 0; +}