Migrating from VC6 to VC9
来源:互联网 发布:淘宝店名大全女装 编辑:程序博客网 时间:2024/05/16 11:03
Migrating from VC6 to VC9
|
A year ago, my company started the migration path of moving from Visual C++ 6.0 to Visual Studio 2005 (VC8). This was mainly done because after Vista was released, it was disclosed that VC6 had limited support on Vista. If and when our development computers needed to be upgraded, XP may have limited availability. So we decided then that moving to the newer compiler was pretty much required.
The problem is that, truthfully, migrating compilers is not something customers care about nor will pay for. So when you have all your developers dedicated to new features and bug fixes, compiler migration always seems to take a back seat.
So throughout 2007, I put in cycles where I can to ensure our code base compiles using VC8. However, in 2008, Visual Studio 2008 (VC9) was released. Since we had not moved to 2005 yet, I decided to take the extra jump to 2008.
In February of 2008, I had all the developers start doing their development using VC9. However, I continued to build our Alpha, Beta and Release builds using VC6. This required some redundant work with projects and some fixes which worked with VC9 that would not work with VC6.
In April, I made the switch for our Alpha builds and later for the new Beta and Release builds to VC9. This went as well as could be expected.
Below are some of the more common issues that we faced.
1. For loop variable scope differences
In VC6, the following is valid:
for (int i = 0; i < 10; i++){}_tprintf(_T("%i/n"), i);
However, in VC9, by default, the above code is not valid. Instead, the variable i is local for the for loop and cannot be referenced outside the loop. To maintain similar functionality, we modified our code to be like the following:
int i = 0;for (i = 0; i < 10; i++){}_tprintf(_T("%i/n"), i);
There is a project setting which we could have set to allow the old behaviour. But I decided to keep the default and modify our code. I think it's better and, IMO, makes more sense.
2. STL iterators behave differently
In VC6, the following used to be valid:
std::list<int> mylist;mylist.push_back(5);std::list<int>::iterator it = mylist.begin();// (*it) == 5it++;// it == mylist.end()it++;// it still == mylist.end()
Now, when debugging, the second ++ will produce an assertion failure and release will crash. Some of our algorithms needed to be updated because they were taking advantage of the fact that you could iterate past end() and still have end().
Another change is the fact that you cannot -- again begin(). Example:
std::list<int>::iterator it = mylist.begin();it--; // would go one before begin()
In hindsight, this is kind of silly, but if the libraries support it, why not use it? We used this because std::list::erase() only takes an iterator, not a reverse_iterator, so to get around this, we could use an interator and work backwards through the list deleting as we went along until we got to the element "before" begin().
After migrating, this also needed to change.
As it turns out, I think the STL changes showed us exactly where many of the problems and crashes were in our code base. For a long time, I felt that many crash reports we were getting were related to this code, but it would never crash here. Instead, it invalidated some data somewhere and would crash later on making debugging, especially remotely, nearly impossible. These changes ensured that improper use of STL would crash the software then and there. At first, we faced many crashes in our alpha builds. But after time, the code base became rock solid.
3. Some 3rd-party libraries need to be recompiled
We were using some 3rd-party libraries such as libpng, zlib, libxml. These DLLs needed to be recompiled since they were initially compiled using MSVCRT, but now must use MSVCR90. Not a big deal. Just recompile and re-link.
4. Data type size changes
Some data types changed sizes. For example, time_t moved from 4 bytes to 8 bytes. We cared about this because we were writing some time_t values to file as a 4 byte integer. We had to change our code to use __time32_t and time32() instead. It's possible to set some defines to force time_t to continue to be 4 bytes, but we decided to embrace the change.
5. "Safe" C-library functions
Microsoft added some "safe" versions of many functions such as strcpy(), makepath(), etc. They called them _strcpy_s() and _makepath_s() respectfully. When compiling the old code, many warnings were displayed about using the "unsafe" version and that the "safe" version should be used instead. Again, there is a define that could be set to suppress this warning, but instead I decided to embrace the change. This one I actually liked. In order to accomplish this, I created my own set of these same functions. When compiling against VC6, we linked to my custom versions. When compiling against VC9, we linked to Microsoft's. After it was done, it was painless to maintain.
After implementation, I feared that we'd get many assertions about improper use of the standard C-library functions. However, we've not had one incidence of an issue because of this. I think this is a fantastic change, but it did not help us in actuality.
6. Previous posts related to our migration
- Debugging issues with MSVCR90.DLL
- ifstream Has Issues
Looking back, the biggest hit to us was the STL changes. However, the way they were changed forced our code base to improve and become more solid. For this reason, I accept the changes.
Migrating wasn't easy. But now that I've migrated, I'll never go back to VC6 unless absolutely required.
- Migrating from VC6 to VC9
- Migrating TerraLib 3.0 from vc6 to vc7.1
- Migrating from 1.0.x to 1.5 Stable
- Migrating from HttpClient 3.1 to HttpClient 4.0
- Migrating Databases To and From ASM with
- Migrating Queries from One User To Another
- 【书籍推荐】Migrating to Swift from Android
- migrating from ia32 to arm digest
- [转]Migrating From Eclipse to IntelliJ IDEA
- Migrating From Eclipse to IntelliJ IDEA
- Migrating VC6 driver project to VC8 with DDK 2003
- Migrating VC6 driver project to VC8 with DDK 2003
- Hint for migrating NetBeans from Windows to Linux.
- Migrating EventLog Analyzer Data from MySQL to MSSQL Database
- Migrating a Database from ASM to Non-ASM Storage
- Migrating Unit Tests from Selenium to Watir Webdriver
- Initial Considerations for Migrating from Forefront TMG to Forefront UAG
- Migrating Your Android App from Eclipse to Android Studio
- 推荐三篇文章,分别是关于微软企业库、ASP.NET MVC以及SEO优化
- Android 开发环境搭建中--- “An SDK Target must be specified.” 问题解决
- 无意中的发现
- Solaris IP配置
- exec系统调用
- Migrating from VC6 to VC9
- linux帮助命令[man]及退出方法[q]
- 谁能理解我此刻的心
- IBM服务器自动关机的问题, 好像是cpu温度过高的问题, 该如何解决?
- 几个VC6.0到VC9.0的错误解决方案
- javascript跨域访问方式
- Solaris Source Insight: PCI bus driver moduls - npe Part 1
- 嵌入式开发中用到的一些扩展关键字
- SHBrowseForFolder 上的network不能展开???