c:\ TEMP \ TestBed \TestStruct\main.c(18):错误C2143:语法错误: 在''标识符'之前缺少'';'' c:\ TEMP \ TestBed\TestStruct\main.c(18):错误C2065:''f'':未声明 标识符 c:\ TEMP \ TestBed \ TestStruct \ main.c(18):警告C4047:''='':''int'' 的间接等级不同来自''void(__ cdecl *)(MyStruct *)'' c:\ TEMP \ TestBed \ TestStruct \ main.c(19):错误C2063:''f'':不是 函数 构建日志保存在file:// c:\ Temp\TestBed\TestStruct\Debug \BuildLog.htm" TestStruct - 7个错误,1个警告 ........................................... ....... ........ 并且在gcc 3.2.3(mingw)下没有窥视,它编译并且工作正常。 I cannot get the following code to compile under MSVC 2003 or 2005................................................... .........................................#include<stdio.h>struct _MyStruct;typedef struct _MyStruct MyStruct;typedef void (*funcType)(MyStruct *);struct _MyStruct {double x;};void MyFunc(MyStruct *theStruct){printf(" %f ",theStruct->x);}int main () {MyStruct A;A.x = 100.0;funcType f=&MyFunc;f(&A);}.................................................. ..............................Under gcc , no problem . 解决方案 Dnia 18 May 2007 02:50:05 -0700, Nindi napisa3(a):I cannot get the following code to compile under MSVC 2003 or 2005................................................... ........................................#include<stdio.h>struct _MyStruct;typedef struct _MyStruct MyStruct;typedef void (*funcType)(MyStruct *);struct _MyStruct {double x;};void MyFunc(MyStruct *theStruct){printf(" %f ",theStruct->x);}int main () {MyStruct A;A.x = 100.0;funcType f=&MyFunc;f(&A);}.................................................. .............................Under gcc , no problem .Give us some errors from the compiler. I see no "return 0" here but don''tknow whether you forgot to write it here or is just the snippet.--SirMike - http://www.sirmike.orgC makes it easy to shoot yourself in the foot; C++ makes it harder, butwhen you do, it blows away your whole leg. - Bjarne StroustrupOn May 18, 10:50 am, Nindi <[email protected]:I cannot get the following code to compile under MSVC 2003 or 2005................................................... ........................................#include<stdio.h>struct _MyStruct;typedef struct _MyStruct MyStruct;typedef void (*funcType)(MyStruct *);struct _MyStruct {double x;};void MyFunc(MyStruct *theStruct){printf(" %f ",theStruct->x);}int main () { MyStruct A; A.x = 100.0; funcType f=&MyFunc; f(&A);}.................................................. .............................Under gcc , no problem .What compilation errors are you getting?I just compiled it on MS VC++ 2003 and it compiles fine. On 18 May, 10:59, SirMike <[email protected]:Dnia 18 May 2007 02:50:05 -0700, Nindi napisa3(a): I cannot get the following code to compile under MSVC 2003 or 2005. .................................................. ..........................*............... #include<stdio.h> struct _MyStruct; typedef struct _MyStruct MyStruct; typedef void (*funcType)(MyStruct *); struct _MyStruct {double x;}; void MyFunc(MyStruct *theStruct){printf(" %f ",theStruct->x);} int main () { MyStruct A; A.x = 100.0; funcType f=&MyFunc; f(&A); } .................................................. ..........................*.... Under gcc , no problem .Give us some errors from the compiler. I see no "return 0" here but don''tknow whether you forgot to write it here or is just the snippet.--SirMike -http://www.sirmike.orgC makes it easy to shoot yourself in the foot; C++ makes it harder, butwhen you do, it blows away your whole leg. - Bjarne Stroustrup- Hide quoted text -- Show quoted text -I am not sure whether return is neccessary in main, but I aggree itsbetter form to put it in.Here are the errors under 2003.................................................. ............------ Build started: Project: TestStruct, Configuration: Debug Win32------Compiling...main.cc:\TEMP\TestBed\TestStruct\main.c(18) : error C2275: ''funcType'' :illegal use of this type as an expressionc:\TEMP\TestBed\TestStruct\main.c(8) : see declaration of''funcType''c:\TEMP\TestBed\TestStruct\main.c(18) : error C2146: syntax error :missing '';'' before identifier ''f''c:\TEMP\TestBed\TestStruct\main.c(18) : error C2144: syntax error :''<Unknown>'' should be preceded by ''<Unknown>''c:\TEMP\TestBed\TestStruct\main.c(18) : error C2144: syntax error :''<Unknown>'' should be preceded by ''<Unknown>''c:\TEMP\TestBed\TestStruct\main.c(18) : error C2143: syntax error :missing '';'' before ''identifier''c:\TEMP\TestBed\TestStruct\main.c(18) : error C2065: ''f'' : undeclaredidentifierc:\TEMP\TestBed\TestStruct\main.c(18) : warning C4047: ''='' : ''int''differs in levels of indirection from ''void (__cdecl *)(MyStruct *)''c:\TEMP\TestBed\TestStruct\main.c(19) : error C2063: ''f'' : not afunctionBuild log was saved at "file://c:\Temp\TestBed\TestStruct\Debug\BuildLog.htm"TestStruct - 7 error(s), 1 warning(s).................................................. ........And under gcc 3.2.3 (mingw) not a peep, it compiles and works fine. 这篇关于MSVC中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-27 21:58