Objective-C中的typeof,__ typeof和__typeof__之间的区别
在Objective-C中,我经常在处理块等时使用__typeof__(obj)
.为什么不使用__typeof(obj)
或typeof(obj)
.
In Objective-C I often use __typeof__(obj)
when dealing with blocks etc. Why not __typeof(obj)
or typeof(obj)
.
何时使用哪个?
__typeof__()
和__typeof()
是C语言特定于编译器的扩展,因为标准C不包含此类运算符.标准C要求编译器在语言扩展之前加上双下划线(这也是为什么您永远不要为自己的函数,变量等使用前缀的原因)
__typeof__()
and __typeof()
are compiler-specific extensions to the C language, because standard C does not include such an operator. Standard C requires compilers to prefix language extensions with a double-underscore (which is also why you should never do so for your own functions, variables, etc.)
typeof()
完全相同,但是在理解每个现代编译器都支持的情况下,将下划线放在了窗口之外. (实际上,既然考虑到这一点,Visual C ++可能不会.尽管它确实支持decltype()
,但通常提供与typeof()
相同的行为.)
typeof()
is exactly the same, but throws the underscores out the window with the understanding that every modern compiler supports it. (Actually, now that I think about it, Visual C++ might not. It does support decltype()
though, which generally provides the same behaviour as typeof()
.)
这三者均表示同一件事,但都不是标准C语言,因此合格的编译器可能会选择使任何意思有所不同.
All three mean the same thing, but none are standard C so a conforming compiler may choose to make any mean something different.