Mecia:ME333-2013-q4.txt
1. Explain the purpose of an "include guard."
The include guard prevents a header file from being included more than once during compilation of a C file, preventing duplicate definitions of constants, macros, function prototypes, etc. (Note: this is only relevant for compilation of one C file. Each C file is compiled independently. There is no problem if different C files in the same project include the same header file, even without an include guard.)
2. Your file main.c will be compiled to main.o. It uses a function called foo(), defined in helper.c. For main.c to compile to main.o, what is needed by the compiler?
(a) the object code of the function foo() (b) the C code of the function foo() (c) a prototype of the function foo() (d) none of the above
(c). To be able to compile main.c to main.o, the compiler needs to know the types of arguments to the function as well as the return type. It doesn't need the actual C code.
3. Which of the following are NOT appropriate for a header file, according to Chapter 4? There may be more than one.
(a) C code for a function (b) a function prototype (c) a constant (d) a macro (e) definition of a global variable (space allocated) (f) an "extern" declaration (no space allocated) of a global variable defined in C code (g) a new data type
(a) and (e)