关于 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.