推荐款式 [英] Recommended style
问题描述
大家好,
以下是生产代码中推荐的样式 -
....
fp = fopen(" xyz.txt"," r");
if(fp == NULL){
.... < br $>
}
或
fp = fopen(" xyz.txt"," r");
if(!fp){
....
}
谢谢。
Hi all,
Which is the recommended style in production code for the following -
....
fp = fopen("xyz.txt", "r");
if (fp == NULL) {
....
}
OR
fp = fopen("xyz.txt", "r");
if (!fp) {
....
}
Thanks.
推荐答案
怎么样
if((fp = fopen(filename," mode"))= = NULL)
{
//失败
}
" Kelvin Moss" <公里********** @ yahoo.com>在消息中写道
news:11 ********************** @ c13g2000cwb.googlegr oups.com ...
how about
if((fp=fopen(filename,"mode"))==NULL)
{
//failed
}
"Kelvin Moss" <km**********@yahoo.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
大家好,
以下是生产代码中推荐的样式 -
...
fp = fopen(" xyz。 txt"," r");
if(fp == NULL){
...
}
fp = fopen( " xyz.txt"," r");
if(!fp){
...
}
谢谢。
Hi all,
Which is the recommended style in production code for the following -
...
fp = fopen("xyz.txt", "r");
if (fp == NULL) {
...
}
OR
fp = fopen("xyz.txt", "r");
if (!fp) {
...
}
Thanks.
Kelvin Moss写道:
Kelvin Moss wrote:
大家好,
以下是生产代码中推荐的样式 -
...
fp = fopen(" xyz.txt"," r");
if(fp == NULL){
...
}
fp = fopen(" xyz.txt"," r");
if(!fp){
。 ..
}
谢谢。
Hi all,
Which is the recommended style in production code for the following -
...
fp = fopen("xyz.txt", "r");
if (fp == NULL) {
...
}
OR
fp = fopen("xyz.txt", "r");
if (!fp) {
...
}
Thanks.
我认为在这样的情况下,任何一个都可以。它只是
前者更明确的情况,而后者使用了一个着名的C b成语
。
您可能希望在项目中保持一致 - 但要么选择
就足够透明了。 (我更喜欢第二种,但那是纯粹的意见。)
HTH,
- g
-
Artie Gold - 德克萨斯州奥斯汀
http://it-matters.blogspot.com (新帖子12/5)
http://www.cafepress.com/goldsays
I think in a case like this, either one would be just fine; it''s just
the case that the former is more explicit, while the latter employs a
well-known C idiom.
You might want to keep it consistent in a project -- but either choice
is sufficiently transparent. (I prefer the second, but that''s pure opinion.)
HTH,
--ag
--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Alex写道:
怎么样? />
if((fp = fopen(filename," mode"))== NULL)
{
//失败
}
how about
if((fp=fopen(filename,"mode"))==NULL)
{
//failed
}
或相反:
if(NULL ==(fp = fopen(filename,mode))){
/ *失败* /
}
左边的常量使C编译器婊子大约=
而不是==是一个常见的程序员错误,通常
在运行时调试期间需要很长时间才能找到;}
与下面相同:
fp = fopen(文件名,模式);
if(NULL == fp){
/ * failed * /
}
if(!fp)左边不需要常量,因为!是一个
一元逻辑运算符。
- 龙
or, conversely:
if ( NULL == ( fp = fopen( filename, mode ) ) ) {
/* Failed */
}
Constants going on the left makes the C compiler bitch about =
instead of == which is a common programmer error that generally
takes a long time to find during runtime debugging ;}
Same with below:
fp = fopen( filename, mode );
if ( NULL == fp ) {
/* failed */
}
if ( !fp ) doesn''t require constants on the left, since ! is a
unary logic operator.
-- The Dragon
大家好,
以下是生产代码中推荐的样式 -
...
fp = fopen(" xyz。 txt"," r");
if(fp == NULL){
...
}
fp = fopen( " xyz.txt"," r");
if(!fp){
...
}
谢谢。
Hi all,
Which is the recommended style in production code for the following -
...
fp = fopen("xyz.txt", "r");
if (fp == NULL) {
...
}
OR
fp = fopen("xyz.txt", "r");
if (!fp) {
...
}
Thanks.
这篇关于推荐款式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!