Topics
- Preprocessor
- Compiling
- Linking
- GCC
- Declaration vs definition
Class Slides
Resources
Study Questions
- What is the role of the preprocessor?
- (T/F) When you include
#include <stdio.h>
in your code, the definition (function body) for the printf function is included in your code. - (T/F) When you compile two files using
gcc file1.c file2.c
, the compiler will analyze both files together to make sure you are using functions and variables from different files correctly. - Why does the C language use header files?
- Why should you put function prototypes for your helper functions at the top of your .c files?
- (T/F) Global variables should be defined in header files.
- If you are compiling your code, and see the error: “undefined reference to ‘foo’”, what does this mean?
-
If you are compiling your code, and see the error: “multiple definition of ‘current_state’”, what does this mean?
- (T/F) Will this code compile?
#include <stdio.h> int x; int x; int main() { printf("%d\n", x); return 0; }
- (T/F) Will this code compile?
#include <stdio.h> int x; int x = 3; int main() { printf("%d\n", x); return 0; }
- (T/F) Will this code compile?
#include <stdio.h> int x = 3; int x = 3; int main() { printf("%d\n", x); return 0; }
- The following files are compiled and linked using the command
gcc main.c foo.c
. Does this result in a compiler error? Linker error?- main.c:
#include <stdio.h> int main() { int sum = add(3); printf("sum: %d\n", sum); }
- foo.c
int add(int a, int b) { return a + b; }
- main.c:
- The following files are compiled and linked using the command
gcc main.c foo.c
. Does this result in a compiler error? Linker error?- main.c:
#include <stdio.h> int x = 3; int main() { printf("x: %d\n", increment(x)); }
- foo.c
int x = 4; int increment(int x) { return x+1; }
- main.c: