Discussion:
Errors with cstdio, cstring and int &a
(too old to reply)
Rayne
2009-12-04 03:23:59 UTC
Permalink
Hi all,

I'm trying to port code written by someone else from Linux to Windows,
and am having some trouble with the errors reported by the compiler.
I'm using Visual Studio .NET 2003.

I'm getting hundreds of error messages such as

C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include
\cstdio(29) : error C2059: syntax error : ':'
C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include
\cstdio(29) : error C2413: syntax error : missing '{' before ':'
C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include
\cstring(17) : error C2059: syntax error : ':'
C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include
\cstdio(17) : error C2413: syntax error : missing '{' before ':'

What could have caused these? I do have #include <stdio.h> and
<string.h>, and I don't have <iostream> or <iostream.h>.

Another problem I have is that one of the functions is declared as
follows:
BOOL function_name(int &a, int &b);

I get the "error C2059: syntax error: '&'" message. Is passing by
reference not allowed? Would changing this to a pointer (i.e. int *a,
int *b) be the correct way instead?

Thank you.

Regards,
Rayne
Stephan T. Lavavej [MSFT]
2009-12-04 03:52:59 UTC
Permalink
That's a very, very old compiler. VS 2008 SP1 is the latest version.

It sounds like you're compiling C++ as C.

Stephan T. Lavavej
Visual C++ Libraries Developer
Post by Rayne
Hi all,
I'm trying to port code written by someone else from Linux to Windows,
and am having some trouble with the errors reported by the compiler.
I'm using Visual Studio .NET 2003.
I'm getting hundreds of error messages such as
C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include
\cstdio(29) : error C2059: syntax error : ':'
C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include
\cstdio(29) : error C2413: syntax error : missing '{' before ':'
C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include
\cstring(17) : error C2059: syntax error : ':'
C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include
\cstdio(17) : error C2413: syntax error : missing '{' before ':'
What could have caused these? I do have #include <stdio.h> and
<string.h>, and I don't have <iostream> or <iostream.h>.
Another problem I have is that one of the functions is declared as
BOOL function_name(int &a, int &b);
I get the "error C2059: syntax error: '&'" message. Is passing by
reference not allowed? Would changing this to a pointer (i.e. int *a,
int *b) be the correct way instead?
Thank you.
Regards,
Rayne
Igor Tandetnik
2009-12-04 03:53:27 UTC
Permalink
Post by Rayne
I'm trying to port code written by someone else from Linux to Windows,
and am having some trouble with the errors reported by the compiler.
I'm using Visual Studio .NET 2003.
I'm getting hundreds of error messages such as
C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include
\cstdio(29) : error C2059: syntax error : ':'
Your code gets compiled as C rather than C++. Do your source files have a .c extension, by any chance? You can force them to be compiled as C++ with Project | Properties | C/C++ | Advanced | Compile As.
Post by Rayne
Another problem I have is that one of the functions is declared as
BOOL function_name(int &a, int &b);
I get the "error C2059: syntax error: '&'" message. Is passing by
reference not allowed?
Not in C, no.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Rayne
2009-12-04 05:46:56 UTC
Permalink
Post by Igor Tandetnik
Post by Rayne
I'm trying to port code written by someone else from Linux to Windows,
and am having some trouble with the errors reported by the compiler.
I'm using Visual Studio .NET 2003.
I'm getting hundreds of error messages such as
C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include
\cstdio(29) : error C2059: syntax error : ':'
Your code gets compiled as C rather than C++. Do your source files have a .c extension, by any chance? You can force them to be compiled as C++ with Project | Properties | C/C++ | Advanced | Compile As.
Post by Rayne
Another problem I have is that one of the functions is declared as
BOOL function_name(int &a, int &b);
I get the "error C2059: syntax error: '&'" message. Is passing by
reference not allowed?
Not in C, no.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Thanks, compiling it as C++ now removes the errors.

Loading...