C++

From bone.wiki
Jump to navigation Jump to search

Tips

Minimize includes in headers

You should try to include the minimum number of other headers in your own header files. There are several reasons for this:

  • If all header files include many other headers files, which each in turn include many other header files, then compilation times can get very long. And if you change one header, you may suddenly find that practically your entire project needs to be recompiled.
  • By including many headers, which in turn include many other headers, you may be importing stuff you don't want and have no idea about. For example, macro definitions that cause was unexpected behaviour. This can be very hard to track to debug is there is a vast chain of headers to trace.

Minimize use of macros

inline functions, overloaded functions or templated functions

Prefer iostreams to printf and scanf

Don't ignore compiler warnings

Put comments in the appropriate place

Never put 'using namespace' in a header

Don't reinvent the wheel

boost

-string manipulation - platform-independent file path handling - fixed-length integers (e.g 64 bit) See next section.

numerical especially important: lapack

Fixed length integers

Advanced Topics

Forcing a C++ header to use C calling convention

Declaring functions for shared libraries on Windows