gcc v2.95.3 --> VS

P

plize

Hello people,
I have C++ code compiled with GNU compiler gcc version 2.95.3.
which I need to edit and run under windows. (I have access to VS6 and
VS.NET)

What approach is easier?
1) Rewrite it?
2) Add functions so that the original code makes sense?

For example, the following line generates an error:

vector<pair<int, int> > abc;
map<int, vector<int> > xyz;

Thank you
 
D

David Wilkinson

Hello people,
I have C++ code compiled with GNU compiler gcc version 2.95.3.
which I need to edit and run under windows. (I have access to VS6 and
VS.NET)

What approach is easier?
1) Rewrite it?
2) Add functions so that the original code makes sense?

For example, the following line generates an error:

vector<pair<int, int> > abc;
map<int, vector<int> > xyz;

Thank you

plize:

What error? What makes you think there is something wrong with this
code? Except perhaps missing header or std namespace.

In general, VS2003.NET (and probably VC6) are better compilers than gcc
2.95, so you should not be having problems if your code is correct C++.
Don't believe the Linux propaganda that VC compilers are bad; every VC
compiler (except perhaps VS2002) has been cutting edge at the time of
release.

David Wilkinson
 
B

Bruno van Dooren

Hello people,
I have C++ code compiled with GNU compiler gcc version 2.95.3.
which I need to edit and run under windows. (I have access to VS6 and
VS.NET)

What approach is easier?
1) Rewrite it?
2) Add functions so that the original code makes sense?

To add to David's reply:
Recently I had to port a reasonably complex commandline app from linux to
windows.
on linux they used gcc 2.95, on windows I used VC2003.

since it was a console style app that used 99 % ANSI C++, Porting it was
fairly painless.
there were a few things different, for example building a file path or
things like that.

The only bump in the road was that the original programmer used the readsome
function to read data from an input file stream. it turned out that the
behavior in that specific case was undefined in the standard. gcc did one
thing, vc another.

To port the app and test it against known data cost me just 1 day.
So i think you should definitly try to port it without opting for a rewrite.

there is no clear cut answer to your question.
Basically it all depends on the technology used. if that is portable to
windows then you should be good to go.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
P

plize

Well, I am glad my 'problem' can be solved that easily.
It seams IOSTREAM is the missing link.
I got the following errors when using VS.Net 1.1 (Visual C++) :

#include <iostream.h>
ABC fatal error C1083: Cannot open include file: 'iostream.h': No
such file or directory

int BinarySearch(vector<int> aVector, int n );
ABC error C2062: type 'int' unexpected

Path::path( istream& is ) {
ABC error C2065: 'is' : undeclared identifier

vector<int> anotherVector;
ABC error C2143: syntax error : missing ';' before '<'
ABC error C2501: 'Prog::vector' : missing storage-class or type
specifiers
 
G

Guest

Well, I am glad my 'problem' can be solved that easily.
It seams IOSTREAM is the missing link.
I got the following errors when using VS.Net 1.1 (Visual C++) :

#include <iostream.h>
ABC fatal error C1083: Cannot open include file: 'iostream.h': No
such file or directory

int BinarySearch(vector<int> aVector, int n );
ABC error C2062: type 'int' unexpected

Path::path( istream& is ) {
ABC error C2065: 'is' : undeclared identifier

vector<int> anotherVector;
ABC error C2143: syntax error : missing ';' before '<'
ABC error C2501: 'Prog::vector' : missing storage-class or type
specifiers

Try
#include <iostream>

instead of
#include <iostream.h>

I.e. remove the .h extension.
this is also true for other C++ standard library headers, like string,
vector, ...

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
P

plize

Bruno said:
Try
#include <iostream>

instead of
#include <iostream.h>

I.e. remove the .h extension.
this is also true for other C++ standard library headers, like string,
vector, ...

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"

Thank you Bruno,
Thank you all,

Although no error was generated on
#include <vector>

The statement
vector<int> xyz;
does not make sense, as far as Visual C++ 6 is concerned :
error C2143: syntax error : missing ';' before '<'
 
B

Bruno van Dooren

Thank you Bruno,
Thank you all,

Although no error was generated on
#include <vector>

The statement
vector<int> xyz;
does not make sense, as far as Visual C++ 6 is concerned :
error C2143: syntax error : missing ';' before '<'

just a guess, but maybe

using namespace std;

is missing from you cpp file? because that is the namespace where vector is
declared.
if it is not used, the compiler will not know that vector is a templace
class.

you have to put it after the include directive, like this:

#include <vector>
using namespace std;
vector<int> anotherVector;

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
A

adebaene

Although no error was generated on
#include <vector>

The statement
vector<int> xyz;
does not make sense, as far as Visual C++ 6 is concerned :
error C2143: syntax error : missing ';' before '<'

std::vector<int>. All classes from the standard libray are in the "std"
namespace. I'm quite surprised that gcc accepted this code.

Arnaud
MVP - VC
 
P

plize

Thank you all for your help
The number of errors is shrinking...

Now, the following...
int size = 10;
int arrayOfSize[size];

....results in the following errors:
error C2057: expected constant expression
error C2133: 'arrayOfSize' : unknown size
error C2466: cannot allocate an array of constant size 0

Whats the quickest way to fix this?
And how come it was working under GCC?
 
B

Bruno van Dooren

Thank you all for your help
The number of errors is shrinking...

Now, the following...
int size = 10;
int arrayOfSize[size];

...results in the following errors:
error C2057: expected constant expression
error C2133: 'arrayOfSize' : unknown size
error C2466: cannot allocate an array of constant size 0

Whats the quickest way to fix this?
And how come it was working under GCC?

The fix is simple:
change
int size = 10;
to
const int size = 10;

the reason it works with gcc is that gcc sees that size is a compile time
constant, so it is able to determine the size of the array during
compilation. VC sees that size is a regular variable, so it doesn't compile
the code.
making size a const solves it.

btw you latest post
I found it:
int **arrayOfSize = (int **) malloc( size * sizeof(int *));

is not correct. arrayOfSize is an array of pointers to an int, not an array
of ints.
if you just want an array of ints, this would be better:
int *arrayOfSize = (int *) malloc( size * sizeof(int ));

but don't forget to free arrayOfSize when you are done with it, or you will
get a memory leak if you constantly allocate new arrays.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
D

David Wilkinson

I found it:
int **arrayOfSize = (int **) malloc( size * sizeof(int *));

plize:

As others have pointed out, you are probably missing std:: namespace on
vector:

std::vector<int> xyz;

If gcc 2.95 accepts it without the std::, it is wrong. Don't use malloc;
this is two steps backward.

David Wilkinson
 
D

David Wilkinson

Thank you all for your help
The number of errors is shrinking...

Now, the following...
int size = 10;
int arrayOfSize[size];

...results in the following errors:
error C2057: expected constant expression
error C2133: 'arrayOfSize' : unknown size
error C2466: cannot allocate an array of constant size 0

Whats the quickest way to fix this?
And how come it was working under GCC?

plize:

This is C99, which VC does not support (not even VC8). Again, use
std::vector

std::vector<int> arrayOfSize(10);

David Wilkinson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top