Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Bug in MSVC ?

Reply
Thread Tools

Bug in MSVC ?

 
 
Nindi
Guest
Posts: n/a
 
      05-18-2007
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 .

 
Reply With Quote
 
 
 
 
SirMike
Guest
Posts: n/a
 
      05-18-2007
Dnia 18 May 2007 02:50:05 -0700, Nindi napisał(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't
know whether you forgot to write it here or is just the snippet.

--
SirMike - http://www.sirmike.org

C makes it easy to shoot yourself in the foot; C++ makes it harder, but
when you do, it blows away your whole leg. - Bjarne Stroustrup
 
Reply With Quote
 
 
 
 
Keith Halligan
Guest
Posts: n/a
 
      05-18-2007
On May 18, 10:50 am, Nindi <(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
Nindi
Guest
Posts: n/a
 
      05-18-2007
On 18 May, 10:59, SirMike <sirm...@****SPAMMERSpoczta.onet.pl> wrote:
> Dnia 18 May 2007 02:50:05 -0700, Nindi napisał(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't
> know whether you forgot to write it here or is just the snippet.
>
> --
> SirMike -http://www.sirmike.org
>
> C makes it easy to shoot yourself in the foot; C++ makes it harder, but
> when 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 its
better form to put it in.
Here are the errors under 2003
.................................................. ............
------ Build started: Project: TestStruct, Configuration: Debug Win32
------

Compiling...
main.c
c:\TEMP\TestBed\TestStruct\main.c(1 : error C2275: 'funcType' :
illegal use of this type as an expression
c:\TEMP\TestBed\TestStruct\main.c( : see declaration of
'funcType'
c:\TEMP\TestBed\TestStruct\main.c(1 : error C2146: syntax error :
missing ';' before identifier 'f'
c:\TEMP\TestBed\TestStruct\main.c(1 : error C2144: syntax error :
'<Unknown>' should be preceded by '<Unknown>'
c:\TEMP\TestBed\TestStruct\main.c(1 : error C2144: syntax error :
'<Unknown>' should be preceded by '<Unknown>'
c:\TEMP\TestBed\TestStruct\main.c(1 : error C2143: syntax error :
missing ';' before 'identifier'
c:\TEMP\TestBed\TestStruct\main.c(1 : error C2065: 'f' : undeclared
identifier
c:\TEMP\TestBed\TestStruct\main.c(1 : warning C4047: '=' : 'int'
differs in levels of indirection from 'void (__cdecl *)(MyStruct *)'
c:\TEMP\TestBed\TestStruct\main.c(19) : error C2063: 'f' : not a
function

Build 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.





 
Reply With Quote
 
Sumit Rajan
Guest
Posts: n/a
 
      05-18-2007
Nindi wrote:
> I cannot get the following code to compile under MSVC 2003 or 2005.


Compiles fine for me. What errors are you getting?


--
Sumit Rajan <(E-Mail Removed)>
 
Reply With Quote
 
Nindi
Guest
Posts: n/a
 
      05-18-2007
On 18 May, 11:06, Nindi <(E-Mail Removed)> wrote:
> On 18 May, 10:59, SirMike <sirm...@****SPAMMERSpoczta.onet.pl> wrote:
>
>
>
>
>
> > Dnia 18 May 2007 02:50:05 -0700, Nindi napisał(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't
> > know whether you forgot to write it here or is just the snippet.

>
> > --
> > SirMike -http://www.sirmike.org

>
> > C makes it easy to shoot yourself in the foot; C++ makes it harder, but
> > when 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 its
> better form to put it in.
> Here are the errors under 2003
> .................................................. ...........
> ------ Build started: Project: TestStruct, Configuration: Debug Win32
> ------
>
> Compiling...
> main.c
> c:\TEMP\TestBed\TestStruct\main.c(1 : error C2275: 'funcType' :
> illegal use of this type as an expression
> c:\TEMP\TestBed\TestStruct\main.c( : see declaration of
> 'funcType'
> c:\TEMP\TestBed\TestStruct\main.c(1 : error C2146: syntax error :
> missing ';' before identifier 'f'
> c:\TEMP\TestBed\TestStruct\main.c(1 : error C2144: syntax error :
> '<Unknown>' should be preceded by '<Unknown>'
> c:\TEMP\TestBed\TestStruct\main.c(1 : error C2144: syntax error :
> '<Unknown>' should be preceded by '<Unknown>'
> c:\TEMP\TestBed\TestStruct\main.c(1 : error C2143: syntax error :
> missing ';' before 'identifier'
> c:\TEMP\TestBed\TestStruct\main.c(1 : error C2065: 'f' : undeclared
> identifier
> c:\TEMP\TestBed\TestStruct\main.c(1 : warning C4047: '=' : 'int'
> differs in levels of indirection from 'void (__cdecl *)(MyStruct *)'
> c:\TEMP\TestBed\TestStruct\main.c(19) : error C2063: 'f' : not a
> function
>
> Build 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.- Hide quoted text -
>
> - Show quoted text -



But the following compiles fine
.................................................. ............
#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);
return 0;

}
.................................................. ...


 
Reply With Quote
 
Zeppe
Guest
Posts: n/a
 
      05-18-2007
Nindi wrote:
> I cannot get the following code to compile under MSVC 2003 or 2005.


It works fine in MSVC2005 to me.

Regards,

Zeppe
 
Reply With Quote
 
Nindi
Guest
Posts: n/a
 
      05-18-2007
On 18 May, 11:08, Zeppe <zeppe@.remove.all.this.long.comment.email.it>
wrote:
> Nindi wrote:
> > I cannot get the following code to compile under MSVC 2003 or 2005.

>
> It works fine in MSVC2005 to me.
>
> Regards,
>
> Zeppe


This is REALLY wierd !!!
If the source file is called main.cpp it works fine BUT if it is
called main.c it fails

 
Reply With Quote
 
Keith Halligan
Guest
Posts: n/a
 
      05-18-2007
On May 18, 11:14 am, Nindi <(E-Mail Removed)> wrote:
> On 18 May, 11:08, Zeppe <zeppe@.remove.all.this.long.comment.email.it>
> wrote:
>
> > Nindi wrote:
> > > I cannot get the following code to compile under MSVC 2003 or 2005.

>
> > It works fine in MSVC2005 to me.

>
> > Regards,

>
> > Zeppe

>
> This is REALLY wierd !!!
> If the source file is called main.cpp it works fine BUT if it is
> called main.c it fails


As far as I can remember if the extension is just .c, msvc will invoke
the C compiler as opposed to the C++ compiler.

If you go into options I think you can set the compiler to invoke for
your project, I think its under advanced or something like that.

The reason you're getting so many failures is that your project/
solution probably has stdafx.h and that is including one of the
standard C++ header files that cannot be compiled by the C compiler.
Remove stdafx.cpp and stdafx.h from the project and recompile.

 
Reply With Quote
 
Nindi
Guest
Posts: n/a
 
      05-18-2007
On May 18, 11:43 am, Keith Halligan <(E-Mail Removed)> wrote:
> On May 18, 11:14 am, Nindi <(E-Mail Removed)> wrote:
>
> > On 18 May, 11:08, Zeppe <zeppe@.remove.all.this.long.comment.email.it>
> > wrote:

>
> > > Nindi wrote:
> > > > I cannot get the following code to compile under MSVC 2003 or 2005.

>
> > > It works fine in MSVC2005 to me.

>
> > > Regards,

>
> > > Zeppe

>
> > This is REALLY wierd !!!
> > If the source file is called main.cpp it works fine BUT if it is
> > called main.c it fails

>
> As far as I can remember if the extension is just .c, msvc will invoke
> the C compiler as opposed to the C++ compiler.
>
> If you go into options I think you can set the compiler to invoke for
> your project, I think its under advanced or something like that.
>
> The reason you're getting so many failures is that your project/
> solution probably has stdafx.h and that is including one of the
> standard C++ header files that cannot be compiled by the C compiler.
> Remove stdafx.cpp and stdafx.h from the project and recompile.


I am not including any othet header file, the project was set up as an
empty console project

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
MSVC 2003: ctor-try-block error: possible compiler bug ksukhonosenko@yandex.ru C++ 4 09-27-2006 10:04 PM
MSVC++ 6.0 Complier optimization bug?? jryden C++ 11 04-28-2006 04:43 PM
diff between pc-msvc pc-cygwin and svg-GDI - which is fastest vc Firefox 10 02-28-2004 01:05 AM
Problem Compiling Xerces-C 2.3 with MSVC.Net 7.1 Dan XML 0 07-01-2003 11:57 AM



Advertisments