Static, extern and inline in Objective-C

前端 未结 2 980
刺人心
刺人心 2020-12-23 12:17

What do static, extern and inline (and their combinations) mean in Objetive-C using the LLVM compiler?

Also, I noticed that th

2条回答
  •  甜味超标
    2020-12-23 12:39

    What do static, extern and inline (and their combinations) mean in Objetive-C using the LLVM compiler?

    The same as in C, unless you compile as ObjC++ -- then they mean the same as found in C++.

    So here is an introduction for C, but read the links if you are ready to use these because the details are important:


    Extern

    Summary: Indicates that an identifier is defined elsewhere.

    Details: http://tigcc.ticalc.org/doc/keywords.html#extern

    Static

    Summary (value): Preserves variable value to survive after its scope ends.

    Summary (function): Effectively emits unnamed copies - useful for private functions in C, and can be used to escape multiple definition errors when used with inline functions.

    Details: http://tigcc.ticalc.org/doc/keywords.html#static

    Inline

    Summary: Suggests the body of a function should be moved into the callers.

    Details: http://tigcc.ticalc.org/doc/gnuexts.html#SEC93


    Note that inline and static are quite a bit more complex in C++ (like pretty much everything in C++).

    I also found that there are CG_EXTERN and CG_INLINE macros. Should we be using those instead?

    No.

    Instead, you should specify your own, with your own meanings, if you need this type of functionality. CG_EXTERN and CG_INLINE have specific meanings (which may change), and are meant to be used in their defined context -- also, you don't want to have to include a whole handful of frameworks (all CoreGraphics/ApplicationServices/CoreFoundation/etc.) when you want to specify something is extern in a way that works in C and C++.

提交回复
热议问题