9- separate files, independent compilation, header files Flashcards
Executable statements
some corresponding machine code is generated by the compiler
example: assignment statements, looping/branching constructs, function invocations
Non-executable statement
no machine code generated
example: function prototypes, variable and constant declarations, #include directives
include directives
tell the compiler to include specified file. The files included are called include or header files and have extensions .hpp
two forms:
#include <filename> - file is found in standard system-dependent location
#include ”filename.hpp” - file is found in the same directory as the rest of the code
purpose of include files: centralize declarations</filename>
include files may also contain include directives
what to put in include files: non-executable statements
what not to put in include files: executable statements, function definitions
Symbol table
which function code the file contains
External references
which functions the file uses but whose code is missing
entry point
function where the execution starts – main()
linker
locates the object file with the entry point
adds to executable
examines external references of this object file
for each external reference, searches other files/libraries’ symbol tables to find required function
when located, adds to executable
continues this process for other files
Preprocessor directive
starts with hastag symbol #, cause compiler to do manipulation of source file before compilation
#include is a preprocessor directive ‘
not a C++ statement
define [name value]
value textual substitution of name by value
seldom used for primary purpose
do not use #define instead of global constants
problem: #define press 50+5
int myvar = press * 20; // changes order of operations
value may be skipped: #define BIG_NAME
ifdef [name]
true if name defined
ifndef [name]
- true if not
this text is included in compiler processing if true, skipped otherwise
endif
completes #if
Include guards
preprocessor directives used for multiple inclusion protection