由恼火的错误error C2275: 'xxx' : illegal use of this type as an expression所想到的

       在linux下调试一个C,通过,没问题,因为linux是在服务器上,大家公用的,所以都是在

自己的机子上调试好了再拿去跑,但是刚刚一个跑通过的程序,竟然在自己机子的XP VC6下

又跑不过去了(搞笑的是这个C还是在VC下编好的),怎么回事呢,提示是:

error C2275: 'time_t' : illegal use of this type as an expression

如图:


      怎么回事呢,google一下,都没搜到,无意中看到一篇文章很简单,说的是:

      (declaration)must placed on the beginning of function, In this case, the compile option is

key. In VC default compile option, there no problem. But when compile option is strict, this style

of writting can not compile with success.


     难道传说中标准的C编译器是要求定义必须在程序开头定义的是真的?搜了一下相关答

案,好像确实是,是C98标准了,C99都可以的,在C++中,这个要求不是很严格,也就是说

在程序中也可以定义变量。


我试着在函数后声明一个 int i;会产生这个错误:

error C2143: syntax error : missing ';' before 'type'

     这样,我就明白了,把“time_t”提前声明就OK了,确实也通过编译,但是问题来了:

我用的是VC啊,我的编译环境和变量就没有改变过,难道VC会根据后缀名是.C还是.cpp来分

别选取不同的编译器吗?这个还是值得探讨研究一下。
posted on 2011-04-13 13:06  清清飞扬  阅读(10903)  评论(0编辑  收藏  举报