宏函数和inine函数有什么区别? [英] what is difference between macro and inine function.?
本文介绍了宏函数和inine函数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
宏函数和inine函数之间的区别是什么??
what is difference between macro and inine function.?
推荐答案
宏在执行编译之前由C/C ++预处理程序处理.
内联函数类似于普通函数,但是编译器不会生成每次使用该函数时都会调用的单个代码块.相反,只要使用函数,编译器就会插入函数代码.
例子:
Macros are processed by the C/C++ preprocessor before the compilation is performed.
Inline functions are like normal functions, but the compiler will not generate a single block of code that is called each time the function is used. Instead, the compiler inserts the function code whenever the function is used.
An example:
#define DIV_BY_TWO(a) ((a) >> 1)
inline int DivByTwo(int a) { return a >> 1; }
int DivByFour(int a) { return a >> 2; }
int i = 8;
int j = 0;
// The preprocessor replaces this line by
// j = ((i) >> 1);
// which is then passed to the compiler.
j = DIV_BY_TWO(i);
// The compiler generates code using
// i >> 1
j = DivByTwo(i);
// The compiler generates a call to the function DivByFour
j = DivByFour(i);
如果我们谈论的是c或c ++,那么宏是用头文件声明的简单代码,它们像
一样是固定的 #宏Pi = 3.14;
另一方面,内联函数是用于在类或特定代码主体中一次又一次调用函数的函数,但是此函数会增加程序的内存使用量.只是关键字"inline"就可以了.用于该函数的前面使它们成为内联函数.
SQL代码标记已删除
If we talk about c or c++ than macros are the simple codes which are declared with header files and which are fixed like
# macro Pi=3.14;
on the other hand inline functions are the functions which are used to call a function again and again in a class or a specific code body but this functions increases the memory use of programs. Simply a keyword "inline" is used in front of the function to make them a inline function.
SQL-Code tags deleted
这篇关于宏函数和inine函数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文