Comments, Prototypes, Headers & Multiple Source Files Modular Code Comments, Prototypes, Headers & Multiple Source Files
Comments Functions designed to: Be reused Be an abstraction Function comments preserve the abstraction "OK, how do I use this thing?"
Doxygen Format Put /** block comment before function: @brief Description of function. @param NAME what parameter called NAME is for @return What is returned
Review Structured comments Used for: Machine readable Automatic documentation Tooltips in IDE?
Function Prototypes Function Prototype : Function header with no body (followed by ;) Declares a function
Prototypes Can use a declared function even if not defined yet Not needed until linking is done
Function Libraries & Headers Function Library : Collection of functions for use elsewhere in program Header files Place to store high level definitions for a code library Should not have code, just declarations .h extension
Compilation Header tells each file functions exist Code in .cpp so that only one definition is compiled
Finding headers Include with < > looks in compiler defined directories Include with " " looks in your project, then regular directories
Guards Don't want same definitions included twice Preprocessor guard: Easy to do by accident: Include A and B, B also includes A Preprocessor guard: #ifndef : if this symbol not defined, read until #endif #define : define a symbol HELPERS_H made up should be unique