C元素的风格 [英] C elements of style

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

问题描述

大家好,


我正在阅读C Elements of style一书。作者:steve oualline。

在本书中给出了许多指导原则。


以下内容在本书中被视为规则


1)while(1)优先于(;;)

2)使用const优于#define

3)除非保证极高的效率,使用printf而不是putc

&把

现在我的问题是


任何人都可以举例说明上述规则的正当理由.. ????




这些规则在多大程度上是真实的.. ???

解决方案

12月2日,12日:26 * pm,aark ... @ gmail.com写道:


大家好,


我正在经历书中的C风格元素作者:steve oualline。

在本书中给出了许多指导原则。


以下内容在本书中被视为规则


1)* while(1)优先于(;;)



我在这里。这些结构创建了相同的结果,并且

对两者都有意义。有些lints和编译器会在(1)时发出呜呜声,但它们不会为(;;)添加任何噪音。


2 )*使用const优先于#define



这个很明显。如果你不小心的话,#define会意外地改变一些东西。


3)*除非保证极高的效率,否则使用printf而不是putc

& put



废话。如果没有格式字符串,请使用puts()。如果你是输出单个字符的
,请使用putc()。


现在我的问题是


任何人都可以举例说明上述规则的正当理由.. ????


* * * * * * * * * * * * * * * * OR

这些规则在多大程度上是正确的.. ???



我喜欢2号,其他两个用错误的方式擦我。


aa ***** @ gmail.com 写道:


大家好,


我正在阅读C Elements of style一书。作者:steve oualline。

在本书中给出了许多指导原则。


以下内容在本书中被视为规则


1)while(1)优先于(;;)

2)使用const优于#define

3)除非保证极高的效率,使用printf而不是putc

&投票


现在我的问题是


任何人都可以举例说明上述规则的正当理由.. ????




这些规则在多大程度上是正确的.. ???



(1)表示某人的个人偏好,

以规则的形式出现。在我看来,拥有尽可能多的力量

作为缩进三个空格的倍数或adverbAlways

verbUse形容词匈牙利语nounNotation。


(2)已出现在CERT草案中Secure C Coding

标准,那里有一些理由。对于什么

它的价值,我发现理由不能令人信服。不过,这三个规则中的
可能是最具防御性的。


(3)似乎很傻。如果反转(不要将
从printf()切换到putchar()仅仅是为了获得微小的速度增益,那么它可能是有意义的),

但是在使用的实际形式...这个规则制定者是否继续

推荐pow(x,2)而不是x * x,或pow(2,6)而不是64?


-
Er ********* @ sun.com


文章< 0f *************************** ******* @ m36g2000hse。 googlegroups.com>,


> 1)* while(1)优先于(;;)


我在这里对面。构造产生相同的结果,两者的含义是显而易见的。



一位经验丰富的C程序员当然会熟悉两者,但

我不认为for的意思;;)"很明显。它没有跟随空的延续条件为真的其他任何东西。

你能做的最好的事情就是说如果以其他方式运行

就毫无意义。 "而(1)"另一方面,这根本不是特例。


- Richard

-

:wq


Hi all,

I was going through the book "C Elements of style" by steve oualline.
in this book many guidelines are given.

the following were seen in the book as rules

1) while(1) is preferred over for(;;)
2) use of const is preferred over #define
3) unless extreme efficiency is warranted, use printf instead of putc
& puts
now my question is

can anyone give examples for the justification of above rules ..????

OR
To what extent these rules are true..???

解决方案

On Apr 2, 12:26*pm, aark...@gmail.com wrote:

Hi all,

I was going through the book "C Elements of style" by steve oualline.
in this book many guidelines are given.

the following were seen in the book as rules

1) *while(1) is preferred over for(;;)

I am opposite here. The constructs create identical results and the
meaning for both is obvious. Some lints and compilers will whine
about while (1) but they do not add any noise for for(;;).

2) *use of const is preferred over #define

This one is obvious. #define can unexpectedly change something if you
are not careful.

3) *unless extreme efficiency is warranted, use printf instead of putc
& puts

Nonsense. If there is no format string, use puts(). If you are
outputting a single character, use putc().

now my question is

can anyone give examples for the justification of above rules ..????

* * * * * * * * * * * * * * * *OR
To what extent these rules are true..???

I like number 2, and the other two rub me the wrong way.


aa*****@gmail.com wrote:

Hi all,

I was going through the book "C Elements of style" by steve oualline.
in this book many guidelines are given.

the following were seen in the book as rules

1) while(1) is preferred over for(;;)
2) use of const is preferred over #define
3) unless extreme efficiency is warranted, use printf instead of putc
& puts
now my question is

can anyone give examples for the justification of above rules ..????

OR
To what extent these rules are true..???

(1) is an expression of somebody''s personal preference,
in the form of a rule. It seems to me to have as much force
as "indent in multiples of three spaces" or "adverbAlways
verbUse adjectiveHungarian nounNotation."

(2) has appeared in the draft CERT "Secure C Coding
Standard," and some justification is given there. For what
it''s worth, I find the justifications unconvincing. Still,
of the Three Rules this may be the most defensible.

(3) seems silly. It might make sense if inverted ("Don''t
switch from printf() to putchar() just for a tiny speed gain"),
but in the actual form used ... Does this Rulemaker go on to
recommend pow(x,2) instead of x*x, or pow(2,6) instead of 64?

--
Er*********@sun.com


In article <0f**********************************@m36g2000hse. googlegroups.com>,

>1) *while(1) is preferred over for(;;)

I am opposite here. The constructs create identical results and the
meaning for both is obvious.

An experienced C programmer will of course be familiar with both, but
I don''t think the meaning of "for(;;)" is obvious. It doesn''t follow
from anything else that an empty continuation condition is true; the
best you can do is say that it would be pointless if it worked the
other way. "while(1)" on the other hand is not a special case at all.

-- Richard
--
:wq


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

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