C 中的 typeof 运算符 [英] typeof operator in C

查看:25
本文介绍了C 中的 typeof 运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C 中的 typeof 真的是一个运算符吗?
我在想,因为 C 中没有多态性,所以在运行时没有什么可做的.也就是说,typeof 的答案在编译时是已知的.(我想不出在编译时不会知道 typeof 的用法.)所以它看起来更像是一个编译时指令,而不是一个运算符.

Is typeof in C, really an operator?
I'm thinking because there is no polymorphism in C, that there is nothing to do at run-time. That is, the answer to typeof is known at compile-time. (I can't think of a use of typeof that would not be known at compile time.) So it appears to be more of a compile-time directive, than an operator.

typeof 是否使用任何(处理器)运行时(在 GCC 中)?

Does typeof use any (processor) run-time (in GCC)?

推荐答案

由于 typeof 是一个编译器扩展,所以并没有真正的定义,但在 C 的传统中它会是一个运算符,例如 sizeof_Alignof 也被视为运算符.

Since typeof is a compiler extension, there is not really a definition for it, but in the tradition of C it would be an operator, e.g sizeof and _Alignof are also seen as an operators.

您弄错了,C 具有仅在运行时确定的动态类型:变量修改 (VM) 类型.

And you are mistaken, C has dynamic types that are only determined at run time: variable modified (VM) types.

size_t n = strtoull(argv[1], 0, 0);
double A[n][n];
typeof(A) B;

只能在运行时确定.

在 2021 年添加:typeofsizeof 规则相似的很有可能会进入 C23.

Add on in 2021: there are good chances that typeof with similar rules as for sizeof will make it into C23.

这篇关于C 中的 typeof 运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆