演员和左撇子 [英] casts and lvalues

查看:75
本文介绍了演员和左撇子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续关于演员表的讨论,我想知道

你对演员作为左值的毛茸茸主题的意见,即


int main(void)

{

long long a;

char * n;


(char *)a = n;

}



这将在lcc-win32下失败,但MSVC和gcc将会

接受它。我知道标准规定了lcc-win32使用的行为

,但是在几年前关于这个问题的大讨论之后我就离开了这个行为。我修改了它,

和一些人提出了地狱。


这样做有什么问题?我的意思不是通常的

标准所说的但如果接受这个问题会在

语言中出现什么问题?


显然仍然使用gcc和msvc,这似乎不是< b / b
产生任何大问题。


提前感谢您的意见,感谢所有参与讨论的人们b $ b昨天。


jacob

解决方案

jacob navia说:


继续关于演员阵容的讨论,我想知道

你对演员的毛茸茸主题的看法为左撇子



这不是意见问题。他们不合法C.演员会产生一个

的价值,但不是左值。


< snip>


这样做有什么问题?



它没有编译。


我的意思不是通常的

标准是这样说的但如果接受这个问题,会在

语言中出现什么问题?



实施者在C89上跳起来像一只松鼠上的一群饥饿的狗。

但是他们成群结队地离开了C99。我没有突然看到它们

都同意支持特定扩展,所有扩展都具有相同的语法和语义。所以根本问题在于你的

提案是不会被接受的。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日


jacob navia写道:


继续关于演员阵容的讨论,我想知道

你对铸造物作为左值的毛茸茸主题的意见,即

[...]

这样做有什么问题?我的意思不是通常的

标准所说的但如果接受这个问题,会在

语言中出现什么问题?



int a = 1;

void f(double * d){

if(a == 1)* d = 2;

if(a == 2)* d = 0;

}

int main(void){

f(&(double)a);

返回a;

}


什么这个程序会返回吗?


Harald van Dijk写道:


jacob navia写道:
< blockquote class =post_quotes>
>继续关于演员阵容的讨论,我想知道你关于演员阵营的毛茸茸主题的意见,即
[...] <这样做有什么问题?我的意思不是通常的标准所说的。但如果接受这个问题,会在
语言中出现什么问题?



int a = 1;

void f(double * d){

if(a == 1)* d = 2;

if(a == 2)* d = 0;

}

int main(void){

f(&(double)a);

返回a;

}


什么这个程序会回来吗?



这里没有编译。你似乎想假装一个是双倍的。


f((double *)& a);


至少会编译。


-

Joe Wright

一切尽可能简单,但并不简单。

---阿尔伯特爱因斯坦---


Continuing the discussion about casts, I would like to know
your opinions about the hairy subject of casts as lvalues, i.e.

int main(void)
{
long long a;
char *n;

(char *)a = n;
}

This will fail under lcc-win32, but MSVC and gcc will
accept it. I know that the standard prescribes the behavior
that lcc-win32 uses, but I left that behavior after a big
discussion about this several years ago. I had modified it,
and some people raised hell.

What are the problems of doing this? I mean not the usual
"the standard says so" but what problems would arise within the
language if this would be accepted?

Apparently gcc and msvc are still used, and this doesn''t seem
to produce any big problems.

Thanks in advance for your comments, and I thank all people
that participated in the discussion yesterday.

jacob

解决方案

jacob navia said:

Continuing the discussion about casts, I would like to know
your opinions about the hairy subject of casts as lvalues

It isn''t a matter of opinion. They''re not legal C. A cast yields a
value, but not an lvalue.

<snip>

What are the problems of doing this?

It doesn''t compile.

I mean not the usual
"the standard says so" but what problems would arise within the
language if this would be accepted?

Implementors jumped at C89 like a pack of starving stoats on a squirrel.
But they have stayed away from C99 in droves. I don''t see them suddenly
all agreeing to support a particular extension, all with the same
syntax and semantics. So the fundamental problem would be that your
proposal wouldn''t be accepted.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


jacob navia wrote:

Continuing the discussion about casts, I would like to know
your opinions about the hairy subject of casts as lvalues, i.e.
[...]
What are the problems of doing this? I mean not the usual
"the standard says so" but what problems would arise within the
language if this would be accepted?

int a = 1;
void f(double *d) {
if (a == 1) *d = 2;
if (a == 2) *d = 0;
}
int main(void) {
f(&(double) a);
return a;
}

What would this program return?


Harald van Dijk wrote:

jacob navia wrote:

>Continuing the discussion about casts, I would like to know
your opinions about the hairy subject of casts as lvalues, i.e.
[...]
What are the problems of doing this? I mean not the usual
"the standard says so" but what problems would arise within the
language if this would be accepted?


int a = 1;
void f(double *d) {
if (a == 1) *d = 2;
if (a == 2) *d = 0;
}
int main(void) {
f(&(double) a);
return a;
}

What would this program return?

It doesn''t compile here. You seem to want to pretend a is a double.

f((double*)&a);

will at least compile.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---


这篇关于演员和左撇子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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