typeof(), __typeof(), __typeof__(), -isKindOfClass:的区别

Posted wjwdive

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typeof(), __typeof(), __typeof__(), -isKindOfClass:的区别相关的知识,希望对你有一定的参考价值。

关于  typeof()和 __typeof()  和 __typeof__() ,Stack Overflow 有一段解释,大概意思是,

__typeof() 、__typeof__() 是C语言的编译器特定扩展,因为标准C语言是不含这样的运算符的。标准C要求编译器用双下划线前缀扩展语言。(这也是为什么你不应该为自己的函数,变量加双下划线的原因);

typeof() 运算符也是完全相同。这三个运算符都一样,就是在编译时检查类型的。

还有一点需要注意:

-isKindOfClass: 函数是一个函数,它是在运行时检查一个对象是属于哪一个类的。而typeof()家族是一个编译期类型检查运算符,它不只能检查类,也能检查所有有效的C语言表达式;

-isKindOfClass: is a runtime check on the class of an object. The typeof() family is a compile-time check on the type (not just class) of any valid C expression.

__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() 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().)

All three mean the same thing, but none are standard C so a conforming compiler may choose to make any mean something different.

 

以上是关于typeof(), __typeof(), __typeof__(), -isKindOfClass:的区别的主要内容,如果未能解决你的问题,请参考以下文章

__typeof与typeof

typeof关键字简介 -rtti

测试数据类型函数typeof( )的用法

数值转换题

React native - 对象作为 React 子对象无效(发现:带有键的对象 $$typeof, type, key, ref, props, _owner, _store)

类静态端“typeof _Readable”错误地扩展了基类静态端“typeof Readable”