error C2143: syntax error : missing ';' before '.'
来源:互联网 发布:做淘宝联盟赚钱吗 编辑:程序博客网 时间:2024/05/19 11:49
在编译C文件时,出现以下错误:
error C2143:syntax error : missing ';' before 'type'
但在CPP文件里,却没出错。测试代码如下:
#include "stdafx.h"
#include "cv.h"
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
CvMat*mat=cvCreateMat(3,3,CV_32FC1 );
cvZero(mat);//将矩阵置0
//CV_MAT_ELEM( *mat, float,2, 0 )=11.0;
cvmSet(mat,2,0,11.0);
float f_elem;
//f_elem=CV_MAT_ELEM( *mat, float,2, 0 );
f_elem=cvmGet( mat, 2, 0 );
printf("%f",f_elem);
return 0;
}
在C文件里面,将声明语句
float f_elem;
放在最前面,即 CvMat*mat=cvCreateMat(3,3,CV_32FC1 )的前面,这时,编译通过。
这个问题在vc编译c++程序,或者gcc编译c程序的时候都不会出现,仅仅在vc编译c程序的时候才会出现。
error C2143:syntax error : missing ';' before 'type'
但在CPP文件里,却没出错。测试代码如下:
#include "stdafx.h"
#include "cv.h"
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
CvMat*mat=cvCreateMat(3,3,CV_32FC1 );
cvZero(mat);//将矩阵置0
//CV_MAT_ELEM( *mat, float,2, 0 )=11.0;
cvmSet(mat,2,0,11.0);
float f_elem;
//f_elem=CV_MAT_ELEM( *mat, float,2, 0 );
f_elem=cvmGet( mat, 2, 0 );
printf("%f",f_elem);
return 0;
}
在C文件里面,将声明语句
float f_elem;
放在最前面,即 CvMat*mat=cvCreateMat(3,3,CV_32FC1 )的前面,这时,编译通过。
这个问题在vc编译c++程序,或者gcc编译c程序的时候都不会出现,仅仅在vc编译c程序的时候才会出现。
这类问题的解决方法,在C程序中,把变量放在在调用函数(或执行操作)之前。(不知是否所谓的C89标准)
近来写程序时发现了一个问题,用 VC 编译 C语言是 总是提示一个错误:error C2143: syntax error : missing ';' before 'type'。考虑了很久也没有答案,于是上网搜索,终于在一位网友博客中找到了解决办法。解决方法如下:
把所有变量的声明放在可执行代码之前。
出现此问题的原因在于:将文件保存成了 *.c 格式。如果是 cpp 格式就能正常编译。
这是因为:在 ANSI C 或者 C++中,在可执行代码中随时定义变量是允许的,但是在K&R C中是不允许的,因此才会出现这个错误。VC6.0 、VS2008 都是用的 K&R C 来实现 C语言的,因此编译过程中会报错。
- error C2143: syntax error : missing ';' before '*'问题
- error C2143: syntax error : missing ';' before '*....
- error C2143: syntax error : missing ';' before '*.... 解决...
- error C2143: syntax error : missing ')' before '*'
- error C2143: syntax error : missing ';' before '*'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error : missing ';' before '.'
- error C2143: syntax error : missing ';' before '*.... 解决方案
- error C2143: syntax error : missing \';\' before \'type\'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error : missing ';' before '}'
- error C2143:syntax error :missing ‘;’before ‘}’
- error C2143: syntax error : missing ';' before 'namespace'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error: missing ';' before '__stdcall'
- i2c分析
- 很好的watir-webdriver知识分享
- UVaOJ270 - Lining Up
- LCD_TEST.C之Glib_Line函数简化
- POJ 2253 Frogger
- error C2143: syntax error : missing ';' before '.'
- UVaOJ10341 - Solve It
- ruby watir 学习资料汇总
- 二叉树的创建、前/中/后序遍历、按层遍历C语言实现
- UVaOJ10057 - A mid-summer night's dream.
- TCP/IP Monitor监控工具应用
- poj 1051 P,MTHBGWB(字符串,较麻烦)
- Android ActionBar+ViewPager 实现左右滑动Tab
- UVaOJ10706 - Number Sequence