473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Bug in MSVC ?

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 .

May 18 '07 #1
29 2029
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
May 18 '07 #2
On May 18, 10:50 am, Nindi <Nind...@yahoo.co.ukwrote:
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.

May 18 '07 #3
On 18 May, 10:59, SirMike <sirm...@FUCKSPAMMERSpoczta.onet.plwrote:
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(18) : error C2275: 'funcType' :
illegal use of this type as an expression
c:\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' : undeclared
identifier
c:\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 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.

May 18 '07 #4
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 <su*********@gmail.com>
May 18 '07 #5
On 18 May, 11:06, Nindi <Nind...@yahoo.co.ukwrote:
On 18 May, 10:59, SirMike <sirm...@FUCKSPAMMERSpoczta.onet.plwrote:


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(18) : error C2275: 'funcType' :
illegal use of this type as an expression
c:\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' : undeclared
identifier
c:\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 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.- Hidequoted 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;

}
.................................................. ...
May 18 '07 #6
Nindi wrote:
I cannot get the following code to compile under MSVC 2003 or 2005.
It works fine in MSVC2005 to me.

Regards,

Zeppe
May 18 '07 #7
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

May 18 '07 #8
On May 18, 11:14 am, Nindi <Nind...@yahoo.co.ukwrote:
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.

May 18 '07 #9
On May 18, 11:43 am, Keith Halligan <keith.halli...@gmail.comwrote:
On May 18, 11:14 am, Nindi <Nind...@yahoo.co.ukwrote:
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

May 18 '07 #10
On May 18, 11:50 am, Nindi <Nind...@yahoo.co.ukwrote:
On May 18, 11:43 am, Keith Halligan <keith.halli...@gmail.comwrote:
On May 18, 11:14 am, Nindi <Nind...@yahoo.co.ukwrote:
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
Look in the solution explorer and see if the files exist, if they do,
then remove them from the solution. You're not including the files
but thats not to say that the compiler isn't compiling these files.

May 18 '07 #11
Keith Halligan wrote:
Look in the solution explorer and see if the files exist, if they do,
then remove them from the solution. You're not including the files
but thats not to say that the compiler isn't compiling these files.
If you look at the errors you will see that they are not related to any
stdafx. The weird thing is that the error disappear commenting the line
A.x = 100.0;. I'm usually *very* reluctant in considering bugs in the
compiler, but in this case I really can't understand this behaviour.

Regards,

Zeppe
May 18 '07 #12
On May 18, 12:05 pm, Keith Halligan <keith.halli...@gmail.comwrote:
On May 18, 11:50 am, Nindi <Nind...@yahoo.co.ukwrote:


On May 18, 11:43 am, Keith Halligan <keith.halli...@gmail.comwrote:
On May 18, 11:14 am, Nindi <Nind...@yahoo.co.ukwrote:
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

Look in the solution explorer and see if the files exist, if they do,
then remove them from the solution. You're not including the files
but thats not to say that the compiler isn't compiling these files.- Hide quoted text -

- Show quoted text -
They are not part of the solution at all. The only file in the
solution explorer is main.c. Also When i created the project I
selected 'Empty' in the project settings.
Have you been able to compile it as 'main.c'

May 18 '07 #13
Nindi wrote:
struct _MyStruct;
Identifiers beginninig with _ and followed by
an uppercase letter are universally reserved to
the implementation. Do not do this.
May 18 '07 #14
On May 18, 12:16 pm, Ron Natalie <r...@spamcop.netwrote:
Nindi wrote:
struct _MyStruct;

Identifiers beginninig with _ and followed by
an uppercase letter are universally reserved to
the implementation. Do not do this.
ok ... I haven't done much C and tend to stick to C++. I picked up
this practice of nameing structs _xxxxx and then typedef _xxxxx xxxxxx
from Glib
May 18 '07 #15
On May 18, 12:19 pm, Nindi <Nind...@yahoo.co.ukwrote:
On May 18, 12:16 pm, Ron Natalie <r...@spamcop.netwrote:
Nindi wrote:
struct _MyStruct;
Identifiers beginninig with _ and followed by
an uppercase letter are universally reserved to
the implementation. Do not do this.

ok ... I haven't done much C and tend to stick to C++. I picked up
this practice of nameing structs _xxxxx and then typedef _xxxxx xxxxxx
from Glib
main.c
.................................................. ............
struct struct_MyStruct;
typedef struct struct_MyStruct MyStruct;

typedef void (*funcType)(MyStruct *);

struct struct_MyStruct {double x;};
void MyFunc(MyStruct *theStruct){}

int main () {
MyStruct A;
A.x = 100.0;
funcType f=&MyFunc;
f(&A);
return 0;

}
.................................................. ...............
May 18 '07 #16
Ok even simpler :-

main.c ( NOT main.cpp)

.................................................. ..............
struct MyStruct {double x;};
typedef void (*funcType)(struct MyStruct *);
void MyFunc(struct MyStruct *theStruct){}

int main () {
struct MyStruct A;
A.x = 100.0;
funcType f=&MyFunc;
f(&A);
return 0;

}

.................................................. ....

Under VC 2003 & 2005 refuses to compile. The Errors are

.................................................. ................
Compiling...
main.c
c:\TEMP\TestBed\TestStruct\main.c(12) : error C2275: 'funcType' :
illegal use of this type as an expression
c:\TEMP\TestBed\TestStruct\main.c(4) : see declaration of 'funcType'
c:\TEMP\TestBed\TestStruct\main.c(12) : error C2146: syntax error :
missing ';' before identifier 'f'
c:\TEMP\TestBed\TestStruct\main.c(12) : error C2144: syntax error :
'<Unknown>' should be preceded by '<Unknown>'
c:\TEMP\TestBed\TestStruct\main.c(12) : error C2144: syntax error :
'<Unknown>' should be preceded by '<Unknown>'
c:\TEMP\TestBed\TestStruct\main.c(12) : error C2143: syntax error :
missing ';' before 'identifier'
c:\TEMP\TestBed\TestStruct\main.c(12) : error C2065: 'f' : undeclared
identifier
c:\TEMP\TestBed\TestStruct\main.c(12) : warning C4047: '=' : 'int'
differs in levels of indirection from 'void (__cdecl *)(MyStruct *)'
c:\TEMP\TestBed\TestStruct\main.c(13) : 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)

.................................................. .....................

under Mingw (gcc 3.2.3) compiles fine.


May 18 '07 #17
On 18 May, 12:19, Nindi <Nind...@yahoo.co.ukwrote:
On May 18, 12:16 pm, Ron Natalie <r...@spamcop.netwrote:
Nindi wrote:
struct _MyStruct;
Identifiers beginninig with _ and followed by
an uppercase letter are universally reserved to
the implementation. Do not do this.

ok ... I haven't done much C and tend to stick to C++. I picked up
this practice of nameing structs _xxxxx and then typedef _xxxxx xxxxxx
from Glib
You can drop the typedef completely in C++.

struct MyStruct
{
// stuff goes here...
};

is sufficient.

Gavin Deane

May 18 '07 #18
On May 18, 10:50 am, Nindi <Nind...@yahoo.co.ukwrote:
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 .
More and more inclined to think its a bug. Even more simplified

main1.c
.................................................. ................

struct MyStruct {double x;};

void MyFunc(){}

int main () {
struct MyStruct A;
A.x = 100.0;
void (*f)() = &MyFunc;
return 0;

}

.................................................. .................
main2.c
.................................................. ................

struct MyStruct {double x;};

void MyFunc(){}

int main () {
struct MyStruct A;
//A.x = 100.0;
void (*f)() = &MyFunc;
return 0;

}

.................................................. .................
main3.c
.................................................. ................

struct MyStruct {double x;};

void MyFunc(){}

int main () {
struct MyStruct A;
A.x = 100.0;
//void (*f)() = &MyFunc;
return 0;

}

.................................................. .................

main1.c fails to compile under VS 2003 & 2005 , main2.c and main3.c
compile fine.

All compile under gcc fine.



May 18 '07 #19
* Nindi:
.................................................. .............
struct MyStruct {double x;};
typedef void (*funcType)(struct MyStruct *);
void MyFunc(struct MyStruct *theStruct){}

int main () {
struct MyStruct A;
A.x = 100.0;
funcType f=&MyFunc;
f(&A);
return 0;

}

.................................................. ...

Under VC 2003 & 2005 refuses to compile. The Errors are

.................................................. ...............
Compiling...
main.c
c:\TEMP\TestBed\TestStruct\main.c(12) : error C2275: 'funcType' :
illegal use of this type as an expression
In C declarations must come before other statements in the block.

You can fix that by using an inner block (curly braces).

Or you can compile as C++ instead of as C.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 18 '07 #20
On May 18, 1:23 pm, "Alf P. Steinbach" <a...@start.nowrote:
* Nindi:


.................................................. .............
struct MyStruct {double x;};
typedef void (*funcType)(struct MyStruct *);
void MyFunc(struct MyStruct *theStruct){}
int main () {
struct MyStruct A;
A.x = 100.0;
funcType f=&MyFunc;
f(&A);
return 0;
}
.................................................. ...
Under VC 2003 & 2005 refuses to compile. The Errors are
.................................................. ...............
Compiling...
main.c
c:\TEMP\TestBed\TestStruct\main.c(12) : error C2275: 'funcType' :
illegal use of this type as an expression

In C declarations must come before other statements in the block.

You can fix that by using an inner block (curly braces).

Or you can compile as C++ instead of as C.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?- Hide quoted text -

- Show quoted text -
That Worked !!!

I put the Variable declarations at the begining of the function and it
compiled.

Is that part of the standard ?

May 18 '07 #21
Alf P. Steinbach wrote:
In C declarations must come before other statements in the block.

You can fix that by using an inner block (curly braces).

Or you can compile as C++ instead of as C.
Alf, you're the man! I feel so stupid not to have noticed that, having
seen that removing the line A.x = 100; it was working! :P

Regards,

Zeppe
May 18 '07 #22
On May 18, 1:23 pm, "Alf P. Steinbach" <a...@start.nowrote:
* Nindi:


.................................................. .............
struct MyStruct {double x;};
typedef void (*funcType)(struct MyStruct *);
void MyFunc(struct MyStruct *theStruct){}
int main () {
struct MyStruct A;
A.x = 100.0;
funcType f=&MyFunc;
f(&A);
return 0;
}
.................................................. ...
Under VC 2003 & 2005 refuses to compile. The Errors are
.................................................. ...............
Compiling...
main.c
c:\TEMP\TestBed\TestStruct\main.c(12) : error C2275: 'funcType' :
illegal use of this type as an expression

In C declarations must come before other statements in the block.

You can fix that by using an inner block (curly braces).

Or you can compile as C++ instead of as C.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?- Hide quoted text -

- Show quoted text -
Thanks very much . I never actualy knew this. But I do now !!!

I consistent behaviour with gcc -pedantic-errors

May 18 '07 #23
On May 18, 2:30 pm, Nindi <Nind...@yahoo.co.ukwrote:
On May 18, 1:23 pm, "Alf P. Steinbach" <a...@start.nowrote:
* Nindi:
.................................................. .............
struct MyStruct {double x;};
typedef void (*funcType)(struct MyStruct *);
void MyFunc(struct MyStruct *theStruct){}
int main () {
struct MyStruct A;
A.x = 100.0;
funcType f=&MyFunc;
f(&A);
return 0;
}
.................................................. ...
Under VC 2003 & 2005 refuses to compile. The Errors are
.................................................. ...............
Compiling...
main.c
c:\TEMP\TestBed\TestStruct\main.c(12) : error C2275: 'funcType' :
illegal use of this type as an expression
In C declarations must come before other statements in the block.
You can fix that by using an inner block (curly braces).
Or you can compile as C++ instead of as C.
That Worked !!!
I put the Variable declarations at the begining of the function and it
compiled.
Is that part of the standard ?
Yes and no. First, as Alf said, it's a question of C, not C++.
If you really want to compile C, and not C++, you should ask in
comp.lang.c, and not here.

Second, the current C standard does NOT require declarations to
come before other code. But this change was introduced in C99,
and many C compilers, apparently, don't implement the new
standard yet. (FWIW: I seem to recall hearing that Microsoft's
policy with regards to C is just to ignore it---VC++ is sold as
a C++ compiler, and any C support is more or less "as is", left
over from earlier versions of the compiler when they did support
C.)

The reason gcc compiles the code, of course, is that they also
take C seriously, and are moving toward full C99 compliance.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

May 18 '07 #24
Nindi wrote:
I cannot get the following code to compile under MSVC 2003 or 2005.

.................................................. ........................................
#include<stdio.h>

struct _MyStruct;
Your program is ill-formed. Any identifier with a leading underscore
followed by an uppercase letter is reserved to the implementation. You
are not allowed to use them.
typedef struct _MyStruct MyStruct;
This is a C-ism. In C++ you'd just declare

struct MyStruct { /* contents here */ };

And use MyStruct directly.
>
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 .
May 18 '07 #25
Nindi wrote:
Ok even simpler :-

main.c ( NOT main.cpp)

.................................................. .............
struct MyStruct {double x;};
typedef void (*funcType)(struct MyStruct *);
void MyFunc(struct MyStruct *theStruct){}

int main () {
struct MyStruct A;
A.x = 100.0;
funcType f=&MyFunc;
f(&A);
return 0;

}

.................................................. ...

Under VC 2003 & 2005 refuses to compile. The Errors are
If you're naming it "main.c", and you're saying it's C code, why are you
posting in comp.lang.c++?
May 18 '07 #26

"Nindi" <Ni*****@yahoo.co.ukwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
They are not part of the solution at all. The only file in the
solution explorer is main.c. Also When i created the project I
selected 'Empty' in the project settings.
Have you been able to compile it as 'main.c'
Honestly, you all are missing something *very* obvious.

int main () {
MyStruct A;
A.x = 100.0;
funcType f=&MyFunc;
f(&A);
}

In C variable declarations after a statement are illegal: declarations in a
function must be grouped *before* any statement.

If you comment A.x you'll get the two variable declarations grouped in the
declaration sections, hence it compiles.

--*PaN!*
May 18 '07 #27
The reason gcc compiles the code, of course, is that they also
take C seriously, and are moving toward full C99 compliance.
Good to know that they chosen to allow this in C99 =)

--*PaN!*
May 18 '07 #28
*PaN!* wrote:
"Nindi" <Ni*****@yahoo.co.ukwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
>They are not part of the solution at all. The only file in the
solution explorer is main.c. Also When i created the project I
selected 'Empty' in the project settings.
Have you been able to compile it as 'main.c'

Honestly, you all are missing something *very* obvious.
Maybe we all missed it because this is a C++ group. If he's got a C
problem, he should post to comp.lang.c.
int main () {
MyStruct A;
A.x = 100.0;
funcType f=&MyFunc;
f(&A);
}

In C variable declarations after a statement are illegal: declarations in a
function must be grouped *before* any statement.

If you comment A.x you'll get the two variable declarations grouped in the
declaration sections, hence it compiles.

--*PaN!*

May 18 '07 #29

"Nindi" <Ni*****@yahoo.co.ukwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
They are not part of the solution at all. The only file in the
solution explorer is main.c. Also When i created the project I
selected 'Empty' in the project settings.
Have you been able to compile it as 'main.c'

Why not use .cpp for your extension or change your
ide to accept .c for c++?
May 19 '07 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eric Brunel | last post by:
Hi all, We're trying to communicate with Microsoft Visual C++ 6.0 via COM to make it perform a few operations. Our main need is to set a breakpoint on a given line in a given file. We ended up...
2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
0
by: Leor Zolman | last post by:
The Intel C++ version of STLFilt (my STL Error Message Decryptor utility) has now been updated to support Intel C++ 8 (currently in Beta) along with version 7. All three MSVC libraries are...
2
by: Robert Oschler | last post by:
Need help with HEAP CORRUPTION and my MSVC 6 DLL I have a MSVC 6 DLL that I've written. It is used heavily by a Delphi 6 app I've written. For two months everything has been working fine. ...
8
by: Chris Stankevitz | last post by:
I can't tell you how frusterated I and my coworkers are with "MSVC 7.1 .net 2003" (what am I supposed to call this thing anyway?). Compiling and linking take twice as long with "MSVC 7.1 .net...
6
by: Uli | last post by:
Hello, I'm trying to use a DLL (by static linking) which was compiled with Borland C++Builder (BCB) in Visual C++ (Visual-Studio 2003). All functions are declared with the directive 'extern...
6
by: ma | last post by:
Hello, Some questions about upgrading to MSVC 2008. 1- I am using MSVC2005, Do you recommend that I upgrade to MSVC 2008 Beta 2? 2- When the MSVC2008 will be officially release? 3- Where...
17
by: fl | last post by:
Hi, I am learning C++ from the following C++ website, which has some very good small examples. For the second Fraction example, which has five files: Main.cpp Fraction.cpp Fraction.h...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
3
by: ameyav | last post by:
I have migrated a c++ project from msvc 7.1 using boost 1.32 to msvc 9 using boost 1.38. I have however noticed that the binary compiled under msvc 9 is almost 25% slower than the one compiled...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.