W [9.1] What is the inline function? The inline function is a function that will be inserted into the caller code stream, just like a #define macro, the inline function optimizes the calling process in the calling process by avoiding calling yourself and (especially) by compiling in the calling process (process integration) To achieve the effect of promoting performance.
[9.2] Inline function is if the security and speed balance? In C, you can reach a "packaged structure" by placing a VOID * in the structure, in which case Void * points to the actual data that the user does not know in the structure. The user of such a structure does not know how to explain the content points to the VOID *, but will automatically convert these functions to the appropriate type from the VOID * type. This gives a form of package.
Unfortunately, it has lost the type of security, and it also enters the data to access each corner in the structure (if you allow direct access to the structure, anyone can access them, because They need to know how they analyze what to point to void *, which will make it more difficult to change the data structure.
The C class allows the function to call the extended inline. This allows you to package safely, and ensure fast direct access. In addition, the parameter type of these inline functions is checked by the compiler, which is for C An improvement in the #define macro.
[9.3] Why should I use the inline function? Instead of using the original #define macro?
Because #define macro is very bad in four aspects (here is not found, more regret)
Unlike #define macro, the inline function can avoid the macro mistake of the name of the wolf, because the inline function always matches each parameter once. In other words, calling the intraline function is just as a regular expression like a regular expression, just faster:
// Macro #define unsafe (i) (i)> = 0? (I): - (i)): - (i))
// Inline INT SAFE (INT I) {RETURN I> = 0? I: -i;}
INT f ();
Void Usercode (int x) {int ANS;
ANS = Unsafe (x ); ANS = unsafe (f ());
ANS = SAFE (x ); ANS = SAFE (f ());}
Unless the macro is that the type of parameter is checked, unnecessary sessions will be properly processed.
Macro your procedure is unfavorable, unless you don't allow, don't use them!
[9.4] How do you let the compiler identify the inline function of a non-member function? When you declare an inline function, it looks like a normal function: Void F (INT I, CHAR C) But when you define an inline function, you put the definition of the function plus the inline keyword When you, the definition is put into the header file:
Inlinevoid F (INT I, CHAR C) {// ...} Note: Placing a function of a function in a header file is a rule. Unless the function is only called in a separate CPP file. Special, if you put the inner function in a CPP file, you call it from other CPP files, you will get a "unresolved External" error in the connector.
[9.5] How do you let the compiler identify an inline member function? When you define a member function, it looks like an ordinary member function:
Class Fred {public: Void F (INT I, CHAR C);
But if you define an inline member function, you have to use the Inline keyword before the function definition, and put this definition in a header file, Inlownevoid Fred :: F (INT I, CHAR C) {/ / ...}
Note: Putting a function's definition in a header file is a rule. Unless the function is only called in a separate CPP file. Special, if you put the inner function in a CPP file, you call it from other CPP files, you will get a "unresolved External" error in the connector. [9.6] Is there another way to let the compiler identify an inline member function? Yes! When defining a member function within a class, it is equivalent to a built-in function:
Class Fred {public: Void F (INT I, CHAR C) {// ...}};
Although this is more simple for people who write this class, this is more difficult for all readers because it is mixed what is a class with this class to implement it. Because of this confusion, we usually define member functions outside the class with the inline keyword. This understanding has the following significance: in a world-oriented world, there are many people use your class, but only one person will write it (yourself), so you should do some to make more Things to benefit, do not allow very few people to benefit.
[9.7] Is the inline function be sure to make your program performance better? no.
Note that the excessive application of the intraday function will cause the code to be swollen, which will make the performance of the paging platform to decrease.