Inline
In some frameworks in iOS, static inline is a keyword combination that often occurs.
- Static does not have to say more, indicating that it is applied in the current file, such as static A, and that static a can appear in other files. Errors that do not cause duplicate names.
- inline. Inline functions.
- Role: Replace macro. (If you look at the frame, see the inline puzzled, search this article, see here can not see the following details)
- When inline is present in the frame, such as the yykit frame. We can see that it appears in the. h file with a little observation. such as:
static Inline cgfloat cgfloatfrompixel ( cgfloat value) {return Value/yyscreenscale ();} //yyscreenscale () method Description: cgfloat Yyscreenscale () {static cgfloat scale; static dispatch_once_t Oncetoken; dispatch_once (&oncetoken, ^{scale = [UIScreen Mainscreen].scale;}); return scale;}
Although the static inline modifier is a function (or method, Swift comes out, I think the method = = function, friends do not have to use the words, despise my generation). But it is here that you can use Cgfloatfrompixel as a macro.
Of course, the inline function differs from a macro, and inline can:
- To solve the problem of function call efficiency:
- The call between functions is a call between memory addresses and returns the address of the original function when the function call is complete. function calls have time overhead, and inline functions are meant to solve this problem.
- Without inline-modified functions, the call command appears in the assembly. Calling the Invoke command is required:
- (1) Place the address of the next instruction in the stack
- (2) and the starting address of the subroutine into the PC (so that the next instruction of the CPU will be transferred to execute the subroutine).
Conclusion why can inline replace macros?
Description of inline inline functions
- 1. The inline function is just the application we provide to the compiler, and the compiler does not necessarily take the inline form to invoke the function.
- 2. Inline functions cannot host large amounts of code. If the function body of the inline function is too large, the compiler automatically discards the inline.
- 3. Loop statements or switch statements are not allowed in inline functions.
- 4. The definition of an inline function must precede the call.
Resources:
Http://stackoverflow.com/questions/11985307/static-extern-and-inline-in-objective-c
http://tigcc.ticalc.org/doc/gnuexts.html#SEC93
Wen/Fan Lu (Jane book author)
Original link: http://www.jianshu.com/p/d557b0831c6a
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
An explanation of inline functions of IOS OC Inline