表达式的类型 [英] type of an expression

查看:114
本文介绍了表达式的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


是否可以确定表达式的类型?类似

运算符sizeof但类型...


例如:


typeof(5.0) - - >返回双倍

typeof(5 + 7) - >返回" int"


hello

is it possible to determine the type of an expression? something like
operator sizeof but for types...

for example:

typeof(5.0) --> returns "double"
typeof(5+7) --> returns "int"

etc.

推荐答案

2006-03-26,fctk< - >写道:
On 2006-03-26, fctk <-> wrote:
你好

是否可以确定表达式的类型?类似于
运营商sizeof但类型......

例如:

typeof(5.0) - >返回double
typeof(5 + 7) - >返回" int"

等。
hello

is it possible to determine the type of an expression? something like
operator sizeof but for types...

for example:

typeof(5.0) --> returns "double"
typeof(5+7) --> returns "int"

etc.




因为猜测,没有任何类型信息的证据

与对象数据一起存储,然后是否。


类型信息被存储。在用于

的句柄(变量)中访问该数据:因此可以通过演员阵容丢失,


有兴趣听到任何不同的内容,因为我'从未见过或

在C中使用了运行时类型检查。



Since, taking a guess, there is no evidence of any type information
being stored with the object data then no.

The type information is "stored" in the handles (variables) used to
access that data : and can therefore be lost through casts,

Will be interested to hear anything different as I''ve never seen or
used runtime type checks in C.


2006-03-26,Richard G. Riley < RG **** @ gmail.com>写道:
On 2006-03-26, Richard G. Riley <rg****@gmail.com> wrote:
2006-03-26,fctk< - >写道:
On 2006-03-26, fctk <-> wrote:
你好

是否可以确定表达式的类型?类似于
运营商sizeof但类型......

例如:

typeof(5.0) - >返回double
typeof(5 + 7) - >返回int


由于猜测,没有任何类型信息的证据与对象数据一起存储,然后没有。
hello

is it possible to determine the type of an expression? something like
operator sizeof but for types...

for example:

typeof(5.0) --> returns "double"
typeof(5+7) --> returns "int"

etc.
Since, taking a guess, there is no evidence of any type information
being stored with the object data then no.




是的,但他指的是表达式的类型 - 这在

编译时已知。 *(int *)& f的类型是int,并且没有未定义的行为

将被调用,就像当前将

表达式传递给sizeof时调用none一样运营商。

类型信息是存储的。在用于访问该数据的句柄(变量)中:因此可以通过演员表丢失,

将有兴趣听到我从未见过的任何不同的内容或
在C中使用了运行时类型检查。



Yeah, but he''s referring to the type of an expression - this is known at
compile time. The type of *(int *)&f is int, and no undefined behavior
would be invoked just like none is invoked currently when passing that
expression to the sizeof operator.
The type information is "stored" in the handles (variables) used to
access that data : and can therefore be lost through casts,

Will be interested to hear anything different as I''ve never seen or
used runtime type checks in C.




他不是在谈论运行时类型检查 - 类型操作符在表达式上工作

,不是内存的碎片,而且是一种常见的扩展。



He''s not talking about runtime type checks - the typeof operator works
on expressions, not blobs of memory, and is a common extension.


< fctk< - >>写道:
<fctk <->> wrote:
是否有可能确定表达式的类型?类似于
运营商sizeof但类型......

例如:

typeof(5.0) - >返回double
typeof(5 + 7) - >返回" int"
is it possible to determine the type of an expression? something like
operator sizeof but for types...

for example:

typeof(5.0) --> returns "double"
typeof(5+7) --> returns "int"




没有这样的语言功能。但是,重要的是要注意

类型,根据定义,在编译时总是可以静态确定

时间,所以从来没有必要确定使用

运算符的类型。您只需查看操作数的类型,并应用

语言规则来确定结果类型。


但是,这些规则可能令人困惑,特别是在Java 1.5中。

我不确定它是否对操作员有帮助,因为Java 1.5

有各种类型的'语言语法甚至可以表达。


-
www.designacourse.com

最简单的培训方式......任何地方。


Chris Smith - 首席软件开发人员/技术人员培训师

MindIQ公司



There is no such language feature. However, it''s important to note that
types, by definition, are ALWAYS statically determinable at compile
time, so there''s never strictly a need to determine the type using an
operator. You just look at the types of the operands, and apply the
language rules to determine the resulting type.

Granted, though, those rules can be confusing, especially in Java 1.5.
I''m not sure it''d help to have the operator then, though, as Java 1.5
has various types that aren''t even expressable in language syntax.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


这篇关于表达式的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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