为什么const没有类型编译? [英] Why const without type compiles?

查看:61
本文介绍了为什么const没有类型编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么编译以下代码(mingw32-gcc 3.4.5)

有任何警告/错误?提前致谢。

#include< stdio.h>


const bufSz = 3; / *没有类型? * /


int main(无效){


int buf [bufSz];


返回0;

}

Why the following code is compiled (mingw32-gcc 3.4.5)
with any warning/error? Thanks in advance.
#include <stdio.h>

const bufSz = 3; /* without type? */

int main( void ) {

int buf[ bufSz ];

return 0;
}

推荐答案

nembo kid写道:
nembo kid wrote:

为什么编译以下代码(mingw32-gcc 3.4.5)

有任何警告/错误?提前致谢。


#include< stdio.h>


const bufSz = 3; / *没有类型? * /


int main(无效){


int buf [bufSz];


返回0;

}

Why the following code is compiled (mingw32-gcc 3.4.5)
with any warning/error? Thanks in advance.
#include <stdio.h>

const bufSz = 3; /* without type? */

int main( void ) {

int buf[ bufSz ];

return 0;
}



使用lcc-win编译,我得到

警告tconst.c:3没有指定类型。默认为int

0错误,1警告


你确定没有得到一些诊断吗?你转了

编译器的所有警告吗?

-

jacob navia

jacob at jacob point remcomp point fr

logiciels / informatique
http://www.cs.virginia.edu/~lcc-win32


在22 Aeustos,00:26,nembo kid< nembo @ kidwrote:
On 22 Aeustos, 00:26, nembo kid <nembo@kidwrote:

为什么以下代码被编译(mingw32-gcc 3.4.5)

有任何警告/错误?在此先感谢。


#include< stdio.h>


const bufSz = 3; / *没有类型? * /


int main(无效){


* * * int buf [bufSz];


* * *返回0;


} - Alyntyyy gizle -


- Alyntyyy g?ster -
Why the following code is compiled (mingw32-gcc 3.4.5)
with any warning/error? Thanks in advance.

#include <stdio.h>

const bufSz = 3; /* without type? */

int main( void ) {

* * *int buf[ bufSz ];

* * *return 0;

}- Alyntyyy gizle -

- Alyntyyy g?ster -



因为它在C89中是隐式int。

Because it is implicit int in C89 .


Ali Karaali写道:
Ali Karaali wrote:

在22 Aeustos,00:26,nembo kid< nembo @ kidwrote:
On 22 Aeustos, 00:26, nembo kid <nembo@kidwrote:

>为什么编译以下代码(mingw32-gcc 3.4.5 )
有任何警告/错误?提前致谢。

#include< stdio.h>

const bufSz = 3; / *没有类型? * /

int main(无效){

int buf [bufSz];

返回0;

} - Alyntyyy gizle -

- Alyntyyy g?ster -
>Why the following code is compiled (mingw32-gcc 3.4.5)
with any warning/error? Thanks in advance.

#include <stdio.h>

const bufSz = 3; /* without type? */

int main( void ) {

int buf[ bufSz ];

return 0;

}- Alyntyyy gizle -

- Alyntyyy g?ster -



因为它是C89中的隐式int。


Because it is implicit int in C89 .



不,它是C99中的隐式int,因为如果不是

int buf [bufSz]

会不编译


-

jacob navia

jacob at jacob point remcomp point fr

logiciels / informatique
http://www.cs.virginia.edu / ~lcc-win32


这篇关于为什么const没有类型编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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