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.

 

转载于:https://www.cnblogs.com/wjw-blog/p/8722183.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值