C2143: 在某类型前缺分号--VC里面的各种问题,应该首先查阅msdn

来源:互联网 发布:淘宝分享有礼效果怎样 编辑:程序博客网 时间:2024/06/08 00:07

今天将P_Demo.cpp=>P_Demo.c。

 

里面某函数体定义如下:

就报如下错误

p_demo.c(68) : error C2275: 'TSint32' : illegal use of this type as an expression
        让我去../NY_ipp.h(60) : see declaration of 'TSint32'
p_demo.c(68) : error C2146: syntax error : missing ';' before identifier 'nImageWidth'
p_demo.c(68) : error C2065: 'nImageWidth' : undeclared identifier

而NY_ipp.h中定义TSint32如下:

    typedef signed int TSint32;

这显然是没有任何问题的。去查错误类型C2275,找不到任何信息。

 

以为是程序识别不了我定义的TSint32。没办法,只好将TSint32替换成signed int

 

结果它仍然报错

p_demo.c(68) : error C2143: syntax error : missing ';' before 'type'

 

再去msdn中去查该错误,这下就有戏了。MSDN解释如下:

PRB: Executable Code Between Declarations Causes C2143 or C2144
ID: Q58559

 

SYMPTOMS
In Microsoft C, compiler errors C2143 and C2144 are defined as follows:

C2143: syntax error : missing 'token1' before 'token2'

C2144: syntax error : missing 'token' before type 'type'


CAUSE
You may receive this error message if your program places executable code before a data declaration, an acceptable practice in Kernighan-and-Ritchie C. This practice has been outlawed in later versions of the ANSI drafts.

This error message will normally occur if a required closing curly brace (}), right parenthesis [)], or semicolon (;) is missing. 声明语句放在执行语句后面了,虽然K&R C允许,但是ANSI C不允许!

 

RESOLUTION
Placing all data declarations before all executable code corrects the programming error.


void main( )
{
   int i;
   printf( "Hello world!/n" );
   {
      int j;
   }
}
NOTE: In the C++ language, it is legal to declare data within a block of executable code.

注意:C++中允许在执行语句模块(即一对大括号)中声明数据;

 

MORE INFORMATION
The following code demonstrates this error message:

Sample Code


Compiling this code with a version of Microsoft C prior to C/C++ 7.0 will return the

following error message:
C2144: syntax error : missing ';' before type 'int'


C/C++ version 7.0 and Visual C/C++ issue the following error:
C2143: syntax error : missing ';' before 'type'

 

 

原创粉丝点击