That is, why does C++ support operations that can be used to violate the rules of static (compile-time) type safety?
• 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 That said, it is a good idea to avoid unsafe code like the plague whenever you don’t actually need one of those three features: • 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.
Related Questions
- What are the state laws rules & what is the FLAG TIME formula used to pay Chrystler technitions in california that have there own tools?
- That is, why does C++ support operations that can be used to violate the rules of static (compile-time) type safety?
- Is there a maximum time for which FSF may be used to support an individual?