C/C++ Coding Tips
Local variables
- Define only when and where needed to assist compiler in mapping variables to registers (especially on C6x)
- Give initial values to avoid uninitialized read errors
- Choose names to indicate purpose and data type
- In C, may only be defined at start of new environment
- In C++, may be defined anywhere
- Function arguments as local variables (may be updated)
Reading strings from files using fgets
- Reads N characters or newline, whichever comes first
- Does not guarantee that newline is read
- Does not guarantee that string is null terminated
Define as many constants as possible