- to access hardware directly (e.g. to treat an integer as a pointer to (address of) a device register)
- to achieve optimal run-time and space performance (e.g. unchecked access to elements of an array and unchecked access to an object through a pointer)
- to be compatible with C
- don't use casts
- keep arrays out of interfaces (hide them in the innards of high-performance functions and classes where they are needed and write the rest of the program using proper strings, vectors, etc.)
- avoid void* (keep them inside low-level functions and data structures if you really need them and present type safe interfaces, usually templates, to your users)
- avoid unions
- if you have any doubts about the validity of a pointer, use a smart pointer instead,
- don't use "naked" news and deletes (use containers, resource handles, etc., instead)
- don't use ...-style variadic functions ("printf style")
- Avoid macros excpt for include guards
For an ambitious project to make C++ easier to use and safer without damaging its efficiency or flexibility, see the Core C++ Guidelines.
No comments:
Post a Comment