关于对LHS的类型转换 [英] About the typecasting to the LHS

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

问题描述

可以这样做吗

浮动a;

(int)a = getc();

解决方案

在文章< 11 ********************* @ o80g2000hse.googlegroups中。 com>,
pa********@hotmail.com < pa * *******@hotmail.com写的:


>可以这样做吗
浮动a;
(int)a = GETC();



不,但你可以做到


(int)(a = getc());


在C中,赋值是表达式,所以这将首先进行赋值

,将得到的double转换为int,然后(因为那里

没有别的东西就行了。扔掉int。


你希望(int)a = getc()是什么意思?在许多

平台上,浮点运算(例如,通过getc()静默转换int返回

到赋值的浮点数)仅在

无法操作的专用浮点寄存器

为整数。

-

谨防错误以上代码;我只是证明它是正确的,

没有尝试过。 - Donald Knuth


" pa ******** @ hotmail.com"写道:


>

可以这样做

浮动a;

(int)a = getc();



编号(查看您的手册和/或该组的档案以获取描述

的l-value。 )


嗯,那和getc()需要一个FILE *作为参数。也许你的意思是

getchar()?


你可以使用:


a =(float)getchar() ;


但是,施放浮动是不必要的。


究竟是什么,你_really_试图做什么?
< br $> b $ b -

+ ------------------------- + ------ -------------- + ----------------------- +

| Kenneth J. Brody | www.hvcomputer.com | #include |

| kenbrody / at\spamcop.net | www.fptech.com | < std_disclaimer.h |

+ ------------------------- + --------- ----------- + ----------------------- +

不要 - 邮寄给我:< mailto:Th ************* @ gmail.com>


pa ******** @ hotmail.com 写道:


可以这样做吗

浮动a;

(int)a = getc();



否。你究竟想做什么?由于getc返回一个int,将它分配给浮动类型并尝试将它再次转换为int似乎相当漂亮

对我来说毫无意义。


Can this be done
float a;
(int) a = getc();

解决方案

In article <11*********************@o80g2000hse.googlegroups. com>,
pa********@hotmail.com <pa********@hotmail.comwrote:

>Can this be done
float a;
(int) a = getc();

No, but you could do

(int) (a = getc());

In C, assignments are expressions, so this would do the assignment
first, convert the resulting double to int, and then (because there
is nothing else on the line) throw away the int.

What were you hoping (int) a = getc() to mean? On a number of
platforms, float arithmetic (e.g., silently converting the int returned
by getc() into a float for the assignment) takes place only in
special purpose floating-point registers which cannot be manipulated
as integers.
--
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth


"pa********@hotmail.com" wrote:

>
Can this be done
float a;
(int) a = getc();

No. (Check your manual and/or this group''s archives for a description
of "l-value".)

Well, that and getc() needs a FILE* as an argument. Perhaps you meant
getchar()?

You could use:

a = (float)getchar();

However, the cast to float is unnecessary.

What, exactly, are you _really_ trying to do?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>


pa********@hotmail.com wrote:

Can this be done
float a;
(int) a = getc();

No. What exactly are you trying to do? Since getc returns an int, assigning
it into floating type and trying to cast it to an int again seems pretty
pointless to me.


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

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