C2143: 在某类型前缺分号--VC里面的各种问题,应该首先查阅msdn
2010-04-02 16:45
302 查看
今天将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'
里面某函数体定义如下:
void main_PR_Init() { g_nImageWidth = IMAGE_FIELD_WIDTH; //初始化全局变量NY@20070815 g_nImageHeight = IMAGE_FIELD_HEIGHT; TSint32 nImageWidth = g_nImageWidth;//初始化局部变量NY@20070815 TSint32 nImageHeight = g_nImageHeight; ... }
就报如下错误
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
/* Compile options needed: none */ #include <stdio.h> void main(void) { int i; printf("Hello World/n"); int j; }
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'
相关文章推荐
- 有关apache包里面的BeanUtils.copyProperties 字段类型为Integer或者Double时,自动赋值为默认值的问题随笔
- VC关于子项目包含依赖问题(Dependency of)从msdn中读到的--Subprojects
- 升级到VC 2008之后变体类型问题
- VC++ (VS2008)里面char和LPTSTR的转换问题
- 属性页里面加对话框,该对话框应该为child类型
- 关于int范围中负数最小值的绝对值比整数最大值大初学C,问题源自:为什么C中的int类型(16位)的下溢下限为-32768而上溢上限却是32767。 首先说吧,32767很容易理解,32767=
- infile.getline() infile.get() 出现的问题,还没有解决.换成 getline(infile,str) 就正常了。所以用高级类型更安全,以后应该用高级类型string等
- 带你玩转Visual Studio——带你了解VC++各种类型的工程
- 【整理】MFC下 各种字符串类型之间转换(MSDN及其他写法)
- VC++中DEBUG的一个无法类型转化的问题
- C++中求各种数据类型最大最小值问题
- LeetCode总结,二叉树各种类型问题小结
- vc++ 各种类型转换
- VC开发过程中数据类型不兼容的问题
- 【转】带你玩转Visual Studio——带你了解VC++各种类型的工程
- 使用JavaScriptSerializer进行序列化日期类型应该注意的问题
- mybatis里面参入参数类型错误问题
- 怎么在jira里面修改问题类型方案
- 问题三十三: 编写程序,输出各种基本类型所占用的字节长度。
- vc中LPCTSTR类型的问题解决