什么是typeof运算((C)+ 1)用C [英] what is typeof((c) + 1) in C

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

问题描述

我碰到C中的前pression来到像

I came across an expression in C like

typeof((c) + 1) _tmp = c;

这到底是什么意思?

What exactly does this mean?

感谢您的答复。

仅一个疑问?如果什么C的类型结构的,而不是原始的类型,那么究竟会+1办?

Just one doubt? What if the type of c is struct instead of the primitive types, then what will +1 do?

推荐答案

在普通的C(不是C ++)的的typeof 运算符是一个GCC除了标准。它会告诉你想用括号中的前pression类型的编译器。

The typeof operator in plain C (not C++) is a GCC addition to the standard. It tells the compiler you want to use the type of the expression enclosed in parenthesis.

使用的typeof 如上,您可以使用另一个变量的类型声明引用类型未知的你或者在这方面的变量。它也可以用于铸造

Using typeof as above, you can declare variables of types unknown to you or in that context, using another variable's type as reference. It can also be used for casting.

编辑: + 操作的typeof 有不同的含义。 的typeof((C)+ 1)手段的C类型,或1类型,两者将继续推广后,的。记住这一点,例如,字符在涉及整数运算使用时提升为整数,整数提升到花车,花车双打等。

the + operation inside typeof has a different meaning. typeof((c) + 1) means "the type of c, or the type of 1, whichever would remain after promotion". Remember that, for example, chars are promoted to ints when used in operations involving ints, ints are promoted to floats, floats to doubles, etc.

请注意,只有编译器可以解决此问题:的typeof 不评估,它没有价值,什么都不会发生在运行时

Note that only the compiler can resolve this: typeof doesn't evaluate, it has no value, nothing happens at run-time.

的typeof 的完整描述可以这里找到

这篇关于什么是typeof运算((C)+ 1)用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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