有趣的代码 [英] Interesting code

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

问题描述

发生了我的旧(上千年)c代码。差点忘了我

写的。

这很有意思。 :-)


int sqrt(int no)

{

int t;

no = t * t;

返回t;

}

Happened to see my old (last millennium) c code. Almost forgot that I
wrote it .
It is interesting. :-)

int sqrt(int no)
{
int t;
no = t * t;
return t;
}

推荐答案

你可以告诉我这段代码有什么好玩的吗?

v4vijayakumar写道:
Can u tell me what is interesting in this code ??
v4vijayakumar wrote:

发生了我的旧(上千年)c代码。差点忘了我

写的。

这很有意思。 :-)


int sqrt(int no)

{

int t;

no = t * t;

返回t;

}
Happened to see my old (last millennium) c code. Almost forgot that I
wrote it .
It is interesting. :-)

int sqrt(int no)
{
int t;
no = t * t;
return t;
}


Dh ********* @ gmail.com 排名靠前,但我已经解决了这个问题。他说:
Dh*********@gmail.com top-posted, but I''ve fixed that. He said:

v4vijayakumar写道:
v4vijayakumar wrote:

>发生了看我的旧(上一个千年)c码。几乎忘了我写了它。
这很有意思。 :-)

int sqrt(int no)
{
int t;
no = t * t;
返回t;
}
>Happened to see my old (last millennium) c code. Almost forgot that I
wrote it .
It is interesting. :-)

int sqrt(int no)
{
int t;
no = t * t;
return t;
}



你能告诉我这段代码有什么意思吗?


Can u tell me what is interesting in this code ??



不,没有任何常规的comp.lang.c撰稿人称为u。

(翻译:abbreviating" ;你tou标记你是一个无法支付
甚至拼写你的人。花点时间在
清晰沟通和不看愚蠢的利益。)


以下是主要兴趣点:


1 )函数名称选择入侵实现命名空间,从而调用

未定义的行为;

2)函数名称选择给出了一个误导性的函数

尝试做;

3)t'的值是不确定的,但函数仍然试图使用t'的
值,因此调用未定义的行为;

4)一个参数仅用于赋值,并且该值将在参数本身为l的同时丢失
ost,在

这个函数结束时;

5)从这个函数返回一个不确定的值,从而在任何函数中调用

未定义的行为评估它的调用者;

6)即使所有这些错误都得到修复,该函数仍然需要主要的修复工作(类型选择,范围验证等)。 br />

摘要:它是由一个几年前不太熟悉C或者六年或七年b
的人写的。无论他们是否在此期间吸取了教训,我都不能说b $ b不能说。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:正常服务将尽快恢复。请不要

调整您的电子邮件客户端。

No, there isn''t any regular comp.lang.c contributor called "u".
(Translation: abbreviating "you" to "u" marks you out as someone who can''t
even spell "you" properly. Take the time to type "you" in full, in the
interests of clear communication and of not looking idiotic.)

Here are the principal points of interest:

1) function name choice invades implementation namespace, thus invoking
undefined behaviour;
2) function name choice gives a misleading impression of what the function
tries to do;
3) t''s value is indeterminate, but the function still attempts to use t''s
value regardless, thus invoking undefined behaviour;
4) a parameter is used solely for assigning a value to, and this value will
be lost at the same time that the parameter itself is lost, at the end of
this function;
5) an indeterminate value is returned from this function, thus invoking
undefined behaviour in any caller that evaluates it;
6) even if all those faults were fixed, the function would still need major
repair work (type choices, range validation, etc).

Summary: it was written by someone who didn''t know C very well six or seven
years ago. Whether they have learned their lessons in the meantime, I
cannot say.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.


" Dh ********* @ gmail.com" < Dh ********* @ gmail.comwrites:
"Dh*********@gmail.com" <Dh*********@gmail.comwrites:

v4vijayakumar写道:
v4vijayakumar wrote:

> int sqrt(int no)
{
int t;
no = t * t;
返回t;
}
>int sqrt(int no)
{
int t;
no = t * t;
return t;
}



你能告诉我这段代码有什么意思吗?


Can u tell me what is interesting in this code ??



只是它所说的误解。

-

我一直在旅行车现在已经十多年了。在那段时间里没有一个转到

。我不再需要它们了。我现在甚至没有使用

休息或继续,当然除了在社交场合。而且我不会被带走。 - 理查德希思菲尔德

Just the misconception that it illustrates.
--
"I''ve been on the wagon now for more than a decade. Not a single goto
in all that time. I just don''t need them any more. I don''t even use
break or continue now, except on social occasions of course. And I
don''t get carried away." --Richard Heathfield


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

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