Problems:      (Page 372)

There are two problems with the use of proprocessor macros in C++. The first is also with C: a macro looks like a function call, but does not act like one. This can bury difficult-to-find bugs. The second problem is specific to C++: the preprocessor has no permission to access class member data. This means preprocessor macros cannot be used as class member functions.

There are many subtle bugs examples with MACRO in Page 372.

Inline functions:

Any function defined within a class body is automatically inline, but you can also make a non-class function inline by preceding it with the inline keyword. You must include the function body with the declaration, otherwise the compiler will treat it as an ordinar function declaration.

Inline function implementation mechanism:    (Page 377)

You will almost want to put inline definitions in a header file. When the compiler sees such a definition, it puts the function type and the function body in its symbol table. When you use the function, the compiler checks to ensure the call is correct and the return value is being used correctly, and then substitutes the function body for the function call, thus eliminating the overhead. The inline code does occupy space, but if the function is small, this can actually take less space than the code generated to do an ordinary function call.

The following rules of thumb might help:

inline function must be small;

access function can be inline function.

Limitations:              (Page 390)

There are two situations in which the compiler cannot perform inlining.

Firstyly, the compiler cannot perform inlining if the function is too complicated.

Secondly, the complier also cannot perform inlining if the address of the function is taken implicitly or explicitly.

Three special features in the C preprocessor:

stringizing        #define DEBUG(x) cout << #x " = " << x << endl

string concatenation

token pasting

#define FIELD(a) char* a##_string; in a##_size

class Record{

  FIELD(one);

  FIELD(two);

  FIELD(three);

};

Inline functions的更多相关文章

  1. why inline functions must be put in header files?

    [why inline functions must be put in header files?] 编译中有2个过程:compile.link.先进行compile,compile中把源代码编译成 ...

  2. C++对象模型——Inline Functions(第四章)

    4.5 Inline Functions 以下是Point class 的一个加法运算符的可能实现内容: class Point { friend Point operator+(const Poin ...

  3. 内联函数(Inline Functions)

    影响性能的一个重要因素是内联技巧.内联函数也可称为内嵌函数. 在C++中,函数调用需要建立栈环境,进行参数复制,保护调用现场,返回时,还要进行返回值复制,恢复调用现场.这些工作都是与完成特定任务的操作 ...

  4. The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.

    https://stackoverflow.com/questions/30045871/sorting-the-view-based-on-frequency-in-sql-server Just ...

  5. C++ inline weak symbol and so on

    关于inline这个关键字,听到强调得最多的是,它只是一种对于编译器的建议,而非强制执行的限定. 但事实上,即使这个优化最终由于函数太过复杂的原因没有达成,加上inline关键字(还有在类定义中直接定 ...

  6. Standard C++ Programming: Virtual Functions and Inlining

    原文链接:http://www.drdobbs.com/cpp/standard-c-programming-virtual-functions/184403747 By Josée Lajoie a ...

  7. (转) Functions

    Functions Functions allow to structure programs in segments of code to perform individual tasks. In ...

  8. About Why Inline Member Function Should Defined in The Header File

    About why inline member function should defined in the header file. It is legal to specify inline on ...

  9. 什么是内联函数(inline function)

    In C, we have used Macro function an optimized technique used by compiler to reduce the execution ti ...

随机推荐

  1. HW3.8

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  2. UVa1424–Salesmen(DP)

    题目大意 给定一个包含n(n<=100)个点的无向连通图和一个长度为L的序列A(L<=200),你的任务是修改尽量少的数,使得序列中的任意两个相邻的数或者相同,或者对应图中两个相邻结点 题 ...

  3. 坑爹的IE quirk模式【转】

    调试一个页面,ie下面页面css样式很是奇怪,各种失效.找了半天原因不知道怎么回事.最后在调试工具中发现,文档模式为quirk,改成别的(IE 7|8|9)正常. 为什么会自动选择此文档模式呢? 先看 ...

  4. oracle中exp,imp的使用详解

    http://www.cnblogs.com/yugen/archive/2010/07/25/1784763.html

  5. testlink邮件设置(centos 7)

    上一篇文章在centos 7上安装了testlink(CentOS 7下安装xampp和testlink),本篇进行邮件设置,可在进行testlink密码修改.用例指派时进行邮件通知 1.修改conf ...

  6. Spring Framework 5.0.0.M3中文文档 翻译记录 introduction

    翻译自: http://docs.spring.io/spring/docs/5.0.0.M3/spring-framework-reference/htmlsingle/#spring.tld.ha ...

  7. java反射与代理模式

    流程age: 饭前洗手----> 吃饭 --->饭后洗碗 //吃饭 public interface Dinner { //吃饭方法 public void haveDinner(); } ...

  8. Python 3. 里filter与generator expression的区别

    # -*- coding: utf-8 -*- """ A test to show the difference between filter and genrator ...

  9. PowerShell脚本传递参数

    在编写PowerShell脚本的时候,可以通过给变量赋值的方法输出想要的结果,但这样的话,需要改动脚本内容.其实也可以在脚本中定义参数,然后再在执行脚本的时候对参数赋值,而无需改动脚本内容. 在Pow ...

  10. 读取xml格式文件

    $v = [xml]get-content d:\vmconfig.xml $v.Domain.Computer.Name =========================== $v.GetElem ...