12.29

Effective C++ Scott Meyers

Chapter 5. Implementations

1. Item 30: Understand the ins and outs of inlining.

  Inline is a request to compilers, not a command. The request can be given implicitly or explicitly. The implicit way is to define a function inside a class definition.

  Inline functions must typically be in header files, because most build environments do inlining during compilation. 

  Templates are typically in header files, because compilers need to know what a template looks like in order to instantiate it when it's used.

  Whether a given inline function is actually inlined depends on the build environment you're using - primarily on the compliler.

  If your program takes the address of an inline function, compilers must typically generate an outlined function body for it.

  Most debuggers have trouble with inline functions. This should be no greate revelation. How do you set a breakpoint in a function that isn't there?

  Limit most inlining to small, frequently called functions. This facilitates debugging and binary upgradability, minimize potential code bloat, and maximize the chances of greater program speed.

  Don't declare function template inline just because they appear in header files.

2. Item 31: Minimize compilation dependencies between files.

  

posted @ 2018-12-29 17:14  lefthook  阅读(99)  评论(0)    收藏  举报