本文介绍了变量声明:位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我今天浏览一个教程的时候,我遇到了一个信息

,标准C变量必须在

块的开头处进行decalred。含义:


/ *********************************** *************** ** /

/ * ...通常包含和* /

int var = 1;


if(var = 1){

printf(" hello world \ n");

}


int a = 10;

int b = 30;


printf("%d%d", a,b);

/ *结束归还等。* /

/ ******************** ****************************** ** /


会形成某种形式错误,需要更换为:

/ ******************************** ****************** ** /

/ * ...通常包括和* /

int var = 1;

if(var = 1){

printf(" hello world \ n");

}


{

int a = 10;

int b = 30;

printf("%d %d,a,b);

}

/ *结束返回等。* /

/ ******* ******************************************* ** /


这对我来说是新闻,因为我从未听过或看到过这样的事情。

事实上,我已经假设(但从未确认)C甚至是

装备具有裸露块特征。任何人都可以提供任何洞察力

到这里发生的事情。另外请纠正我,如果我已经错误地预测了我可能有的东西。

Nori

Whilest I was browesing a tutorial today I came across the infromation
that in standard C variables must be decalred at the beginning of a
block. Meaning:

/************************************************** **/
/* ... usual includes and such */
int var = 1;

if(var = 1){
printf("hello world\n");
}

int a = 10;
int b = 30;

printf("%d %d", a, b);
/* end return etc. */
/************************************************** **/

Would form some kind of error and would need to be replaced with:
/************************************************** **/
/* ... usual includes and such */
int var = 1;
if(var = 1){
printf("hello world\n");
}

{
int a = 10;
int b = 30;
printf("%d %d", a, b);
}
/* end return etc. */
/************************************************** **/

This is news to me as I have never heard or seen anything like this.
Infact I have assumed (but have never confirmed) that C was even
equiped with a "naked block" feature. Can anyone offer any insight as
to what is going on here. Also please correct me if I have
misinturpreted someting as I expect that I might have.
Nori

推荐答案




对于C99之前的代码是真的,在C99中修复。


-

Ian Collins。



True for pre C99 code, fixed in C99.

--
Ian Collins.





对于预C99代码为真,在C99中修复。



True for pre C99 code, fixed in C99.




我想指出代码更容易阅读如果所有的

变量声明位于每个块的顶部。它还允许你

轻松查看什么是和不在范围内,假设你缩进每一层

到块。

Of当然,这只是我的偏好。

-

Andrew Poelstra< http://www.wpsoftware.net/blog>


系列中的每个素数作为一个笑话

当我拿到最后一个toke时使所有模式清晰

- 数字(沉没复杂性)



I''d like to point out that code is far easier to read if all the
variable declarations are at the top of each block. It also allows you
to easily see what is and isn''t in scope, assuming you indent each layer
to blocks.
Of course, that is just a preference of mine.
--
Andrew Poelstra <http://www.wpsoftware.net/blog>

Every prime number in a series as a joke
Made all the patterns clear when I took that final toke
-- Numbers (Sunken Complexity)


这篇关于变量声明:位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 12:44