Questions raised
When learning iOS, you encounter a function nsstringfromcgpoint (UIGeometry.h)
Its prototype is Uikit_extern NSString *nsstringfromcgpoint (cgpoint point);
Prototype analysis
nsstring*, Cgpoint good understanding, the former is the library of the string type, the latter is a representation of 2 dimensional plane polygon points on the structure of the body. But what is Uikit_extern?
Find Find
UIKitDefines.h
1 #ifdef __cplusplus 2 #define Uikit_extern EXTERN "C" __attribute__ ((Visibility ("default"))3#else4#define uikit_extern EXTERN __attribute__ ((Visibility ("default"))5#endif6 7 #define Uikit_static_inline STATIC INLINE
Look at the following line
Line1: #ifdef __cplusplus, that is, if you define a __cplusplus macro identifier, define the following (Line2), otherwise define the contents of #else (line4)
line2: #define uikit_extern EXTERN "C" __attribute__ ((Visibility ("default" )),
1. extern "C" is intended to be compatible with previous C programs, telling the compiler to compile (global) functions or variables according to the previous C-compile method, or compile [1] in C + + mode.
eg. C-way compiler function extern void fx (int, int), does not have special handling of function name after compilation function named _fx (. obj file)
But after C + + is compiled, (in order to support overloading) The FX function becomes a function name similar to _fx_int_int, and FX (int, float) is compiled into _fx_int_float (. obj file)
2. __attribute__ is to set the function property (or Variable property, type property), the properties that can be set include
1 packed,cleanup, common,nocommon,deprecated,mode,section,shared,tls_model,transparent_union, etc. [ 2]
The visibility property is to set the visibility of the function of this item as a library when it is used. g++ when compiling, adding the-fvisibility=hidden parameter will set all the default public properties to hidden, causing the out-of-library file to be invisible
3. However, if the __attribute__ ((Visibility ("default" )) function is set, its public property can still be visible externally, not hidden. The visible compilation instruction -fvisibility is the processing of all attribute symbols, while __attribute__ ((Visibility ("default" )) is a set of specific function visibility to avoid collisions [3].
Line3~6: Ignore
Line7: Static inline, #define Uikit_static_inline static
The static keyword modifier indicates that this is a local function and cannot be referenced, linked to, or otherwise protected by the file (other files that have visibility to the file), and the compile phase can force the check
The inline keyword suggests that the compiler will use the function as an inline function, embedding the code inside the function directly at each reference, somewhat like a macro definition, but with a strict type check of the compiler, so it is more secure than the macro definition, but has the same execution speed.
Summarize
Uikit_extern simply, the function is decorated with properties that are compatible with previous C-compiled methods, have extern attributes (out-of-file visibility), public-decorated methods, or are still visible outside the library of variables
Reference
[1] http://www.cnblogs.com/rollenholt/archive/2012/03/20/2409046.html[2] http://blog.csdn.net/juana1/article/ DETAILS/6849120[3] http://blog.csdn.net/mrguanlingyu/article/details/23337885
What is IOS Uikit_extern, __attribute__ ((Visibility ("Default"))?