Migration from Visual C++ 6.0 to 2005 – Part I
In the last few days I’ve been trying to evaluate what would take to port our applications from visual C++ 6.0 to 8.0 a.k.a. 2005. I was not overly concerned, because the projects I’m trying to convert are server side applications having no graphical user interface.
I started by converting one of the project files and trying to compile it with Visual C++2005. I started getting myriad of warnings and errors and figured that cleaning up everything will not be so easy. The first step was to get he code to compile without errors and later on clean up the warnings. I went to the project settings and disabled all warnings and tried to compile again. This time the output from the compiler was a little more manageable and here are some changes that had to be done in order to preserve compilability in both compilers during the transition period.
Links:
Migration from Visual C++ 6.0 to 2005 – Part II
Migration from Visual C++ 6.0 to 2005 – Part III
I will start with some of the very obvious ones. Read on it gets interesting…
Type int is no longer implicit
We used to have some constructs like:
const SomeConstant = 15;
CalulateSomething () {
return 10;
}
Which now no longer compiles and needs to be changed to:
const int SomeConstant = 15;
int CalulateSomething () {
return 10;
}
Scope of in a for loop defined variable
For example the following is no longer valid:
for (int i = 0; i < 100; i++) {
}
// i is no longer valid here in VC2005
So we switched to the following, which will work in both compilers:
int i;
for (i = 0; i < 100; i++) {
}
// i is valid here now
Another option would be to turn off the compiler option, that enforces the rule and the error becomes a warning.