我不值得 [英] I'm not worthy

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

问题描述

我甚至不是程序员中十亿分之一的真正专家(Heathfield,Amdahl,Tisdale等),

我无法'我自己编写了以下日志功能,

但是我发现它很有趣,所以我与

分享它。这是一个简单的函数来计算n:


int log2(int n)

{

int log = 0;


while(n> 1){

n / = 2;

log ++;

}

返回日志;

}


我独自体验这个功能非常好

愉快吗?这不是一个修辞问题;我真的很想知道。一些所谓的专家非常恶意

和背叛,我怀疑他们的工作剥夺了他们对C编程语言的所有乐趣。



他们的损失。


(引用的函数来自_C Programming:A Modern Approach_,

p.185。)

解决方案

2003年7月31日星期四05:16:19 +0000,Steve Zimmerman写道:

这是一个简单的函数来计算n的log 2:

int log2(int n)




是的。当我看到它返回

int时,我停止阅读该功能。

NPV


Steve Zimmerman< st ******@sonic.net>写道:

int log2(int n)
{log / 0;

while(n> 1){
n / = 2;
log ++;
}
返回日志;
}




可爱(虽然我会把这个循环写成


for(; n> 1; n / = 2)log ++;


我自己。


然而,对于真正的代码我甚至不会使用这个函数;我会使用log2()

来自库,理由是虽然它不是C89,但在C99和我的DJGPP版本中都是



请注意C99版本与你的版本冲突,因为它需要并且

返回一个double。重命名你的log2i()将解决这个问题并且在C99数学函数命名系统中完全符合逻辑(参见

log2f()和log2l())。


Richard


>>但是,对于真正的代码我不会'甚至不使用这个功能;我会使用log2()

来自图书馆的理由,虽然它不是C89,但它在C99和我的DJGPP版本中都是



换句话说,你可能不在乎可移植性问题。




为什么你们这些人会拒绝C99标准所以强烈吗?


如果你继续讨论C99的新功能,没有人会使用它。


不要给我任何向后兼容性的废话,C99和C89一样多的是b
。标准。

我很惊讶你们当人们没有中风使用

与K& R C不兼容的功能。为什么可以以

向后兼容的名义避开C99,但不是C89?毕竟,有些机器甚至不支持C89,只有纯粹的K& R。


I''m not even a billionth of the programmer that a
real expert is (Heathfield, Amdahl, Tisdale, et al),
and I couldn''t code the following log function myself,
but I found it interesting, so I am sharing it with
the group. Here is a simple function to calculate
log base 2 of n:

int log2 (int n)
{
int log = 0;

while (n > 1) {
n /= 2;
log++;
}
return log;
}

Am I alone in experiencing this function as exceedingly
pleasant? That''s not a rhetorical question; I''m really
wondering. Some of the so-called experts are so spiteful
and backbiting that I suspect their jobs are depriving them
of all the pleasure of the C programming language.

Their loss.

(The quoted function is from _C Programming: A Modern Approach_,
p. 185.)

解决方案

On Thu, 31 Jul 2003 05:16:19 +0000, Steve Zimmerman wrote:

Here is a simple function to calculate
log base 2 of n:

int log2 (int n)



Yeah right. I stopped reading that function when I saw it returning an
int.
NPV


Steve Zimmerman <st******@sonic.net> wrote:

int log2 (int n)
{
int log = 0;

while (n > 1) {
n /= 2;
log++;
}
return log;
}



Cute (although I''d write the loop as

for (; n>1; n/=2) log++;

myself.

However, for real code I wouldn''t even use this function; I''d use log2()
from the library, on the justification that, though it isn''t C89, it is
both in C99 and in my version of DJGPP.
And note that the C99 version clashes with yours, because it takes and
returns a double. Renaming yours log2i() would solve that and be
perfectly logical within the C99 math function naming system (cf.
log2f() and log2l()).

Richard


>>However, for real code I wouldn''t even use this function; I''d use log2()

from the library, on the justification that, though it isn''t C89, it is
both in C99 and in my version of DJGPP.



In other words, you couldn''t care less about portability issues.



Why do you people resist the C99 standard so strongly?

If you keep bitching about the new features of C99, no one will ever use it.

Don''t give me any backwards compatibility crap, C99 is just as much a
standard as C89.

I''m suprised you people don''t have strokes when people use features that
aren''t compatible with K&R C. Why is it OK to shun C99 in the name of
backwards compatibility, but not C89? After all, some machines don''t even
support C89, only pure K&R.


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

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