青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++ Programmer's Cookbook

{C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

移置c++從6.0到2005

our months ago, Microsoft publicized a list of features that could cause existing Visual C++ apps to break when migrated to Visual Studio 2005. Many of these features are core C++ updates that are meant to bring Visual C++ to full compliance with ISO C++. There's no doubt that these changes are a major improvement over the non-compliant hacks that have been in use since the mid-1990s. The downside is that migrating to Visual Studio 2005 requires a thorough code review—and possibly some repairs. The following sections show some of the code changes required for porting existing C++ apps to Visual Studio 2005.


Your Visual C++ 6.0 apps will not compile when migrated to Visual Studio 2005 unless you fix them. How do you go about it?


Use this check list to locate incompliant code spots and repair them according the following guidelines.

Code Review and Analysis
Earlier versions of Visual C++ literally forced you to write non-compliant C++ code. Therefore, it's unlikely that an existing Visual 6.0 app will compile as-is with Visual C++ 8.0 (the C++ compiler of Visual Studio 2005). Therefore, your first step is to review the code and locate potential problems. Before you make any changes to the code, my advice is to review the entire code base and systematically mark all code sections that might be incompatible with Visual Studio 2005. Only then should you make the necessary repairs. It's better to repair incompliant code in several passes, each dealing with a different category of fixes. For example, your first pass may focus on for-loops, the next pass on exception handling, and so on. There are three reasons for splitting the code repairs to separate sessions:
  • Team Work: Developers specializing in different categories can work on the same code simultaneously.
  • Coding Standards: It's easier to enforce a uniform coding standard when focusing on one feature at a time.
  • Keyword-based Lookup: Each category is typically associated with a specific C++ keyword (e.g., to locate all for-loops, search for the keyword for).
    Code Review and Analysis
    Earlier versions of Visual C++ literally forced you to write non-compliant C++ code. Therefore, it's unlikely that an existing Visual 6.0 app will compile as-is with Visual C++ 8.0 (the C++ compiler of Visual Studio 2005). Therefore, your first step is to review the code and locate potential problems. Before you make any changes to the code, my advice is to review the entire code base and systematically mark all code sections that might be incompatible with Visual Studio 2005. Only then should you make the necessary repairs. It's better to repair incompliant code in several passes, each dealing with a different category of fixes. For example, your first pass may focus on for-loops, the next pass on exception handling, and so on. There are three reasons for splitting the code repairs to separate sessions:
    • Team Work: Developers specializing in different categories can work on the same code simultaneously.
    • Coding Standards: It's easier to enforce a uniform coding standard when focusing on one feature at a time.
    • Keyword-based Lookup: Each category is typically associated with a specific C++ keyword (e.g., to locate all for-loops, search for the keyword for).

Code Fixing
Some of the necessary code fixes are rather straightforward. These include for-loops, pointers to member functions, the deprecated "default to int" rule, and exception handling. Let's see what these all mean.

  • for-loops: In pre-standard C++, variables declared in a for-loop were visible from the loop's enclosing scope. This behavior is still maintained in Visual C++ 6.0:
    
    for (int i=0; i<MAX; i++)
    {
      //..do something
    }
    
    int j=i; //allowed in VC++ 6.0
    
    However, in Visual Studio 2005, the scope of i is restricted to the for-loop. If you want to refer to this variable from the enclosing scope, move its declaration outside the for-loop:
    
    int i=0;
    for (; i<MAX; i++)
    {
      //..do something
    }
    int j=i; //OK
    

    Figure 1. Exception Handling: This image shows how to override the default exception handling command line flag.

  • Declarations of pointers to members: In pre-standard C++, it was possible to take the address of a member function without using the & operator:
    
    struct S
    {
     void func();
    };
    
    void (S::*pmf)() = S::func; //allowed in VC++ 6.0
    
    In Visual Studio 2005, the & is mandatory:
    
    void (S::*pmf)() = &S::func; //OK
    
    Tip: To locate problematic code, search for the tokens ::* and ::.
  • "default to int": Pre-standard C++ (and all C variants predating C99), use the "default to int" rule when declarations of functions and variables do not contain an explicit datatype. This behavior is maintained in Visual C++ 6.0 as the following declarations show:
    
    const x=0; //implicit int
    static num; // implicit int
    myfunc(void *ptr); //implicit return type int
    
    In Visual Studio 2005, you have to specify the datatype explicitly:
    
    const int x=0; 
    static int num; 
    int myfunc(void *ptr);  
    
    Tip: To locate incompliant code of this category, compile your app with Visual Studio 2005 and look for compilation errors about a missing datatype in a declaration.

  • Exception Handling: Older versions of Visual C++ happily mixed standard C++ exceptions with the asynchronous Structured Exception Handling (SEH). Consequently, a catch(...) block might catch not just a C++ exception created by a throw statement, but also an asynchronous SEH e.g., access violation. Not only is this behavior incompliant, it makes debugging more difficult. Visual Studio 2005 fixes this loophole. It's now possible to specify whether a catch(...) handler should catch only C++ exceptions by using the default /EHsc flag (this is the recommended option), or maintain the non-standard behavior of Visual C++ 6.0 by using the /EHa flag (see Figure 1).

Author's Note: The fixes shown here don't reflect all of the changes in Visual Studio 2005. For a complete list, consult Visual Studio 2005 homepage. Also, I have focused on core C++ features. Other Visual C++-specific changes such as multithreaded CRTs, deprecated APIs etc., aren't discussed here.

Code Fixing
Some of the necessary code fixes are rather straightforward. These include for-loops, pointers to member functions, the deprecated "default to int" rule, and exception handling. Let's see what these all mean.
  • for-loops: In pre-standard C++, variables declared in a for-loop were visible from the loop's enclosing scope. This behavior is still maintained in Visual C++ 6.0:
    
    for (int i=0; i<MAX; i++)
    {
      //..do something
    }
    
    int j=i; //allowed in VC++ 6.0
    
    However, in Visual Studio 2005, the scope of i is restricted to the for-loop. If you want to refer to this variable from the enclosing scope, move its declaration outside the for-loop:
    
    int i=0;
    for (; i<MAX; i++)
    {
      //..do something
    }
    int j=i; //OK
    

    Figure 1. Exception Handling: This image shows how to override the default exception handling command line flag.

  • Declarations of pointers to members: In pre-standard C++, it was possible to take the address of a member function without using the & operator:
    
    struct S
    {
     void func();
    };
    
    void (S::*pmf)() = S::func; //allowed in VC++ 6.0
    
    In Visual Studio 2005, the & is mandatory:
    
    void (S::*pmf)() = &S::func; //OK
    
    Tip: To locate problematic code, search for the tokens ::* and ::.
  • "default to int": Pre-standard C++ (and all C variants predating C99), use the "default to int" rule when declarations of functions and variables do not contain an explicit datatype. This behavior is maintained in Visual C++ 6.0 as the following declarations show:
    
    const x=0; //implicit int
    static num; // implicit int
    myfunc(void *ptr); //implicit return type int
    
    In Visual Studio 2005, you have to specify the datatype explicitly:
    
    const int x=0; 
    static int num; 
    int myfunc(void *ptr);  
    
    Tip: To locate incompliant code of this category, compile your app with Visual Studio 2005 and look for compilation errors about a missing datatype in a declaration.

  • Exception Handling: Older versions of Visual C++ happily mixed standard C++ exceptions with the asynchronous Structured Exception Handling (SEH). Consequently, a catch(...) block might catch not just a C++ exception created by a throw statement, but also an asynchronous SEH e.g., access violation. Not only is this behavior incompliant, it makes debugging more difficult. Visual Studio 2005 fixes this loophole. It's now possible to specify whether a catch(...) handler should catch only C++ exceptions by using the default /EHsc flag (this is the recommended option), or maintain the non-standard behavior of Visual C++ 6.0 by using the /EHa flag (see Figure 1).
Author's Note: The fixes shown here don't reflect all of the changes in Visual Studio 2005. For a complete list, consult Visual Studio 2005 homepage. Also, I have focused on core C++ features. Other Visual C++-specific changes such as multithreaded CRTs, deprecated APIs etc., aren't discussed here.
Just in the Nick of Time
Visual Studio 2005 and Visual C++ 6.0 have different Application Binary Interfaces, or ABIs. This means that the same datatype or function may have different binary layouts and mangled names. The different ABIs affect among other things the std::time_t and wchar_t datatypes.

Visual C++ 6.0 treats std::time_t as a 32-bit integer, whereas in Visual Studio 2005 this type is a 64-bit integer. This change might necessitate code updates if your app assumes a 32-bit time_t e.g., hard-coded buffer sizes and format flags (further information on migrating to 64-bit code is available here). Another ABI change affects the representation of the wchar_t type. Up until now, wchar_t has been a typedef synonymous with unsigned short. However, Visual Studio 2005 treats wchar_t as a built-in type. This change might affect the overload resolution of functions:


int _wtolowers(unsigned short *ws);
wchar_t ws[10] = L"Test";
_wtolowers(ws); 
This code compiles with Visual Studio 6.0 but it will break with Visual Studio 2005 because wchar_t * is incompatible with unsigned short *.

All and Sundry
The changes described here affect not just Visual C++ 6.0 code ported to Visual Studio 2005. Rather, they apply to legacy C++ code ported to an ISO compliant C++ compiler in general. The fear from these changes has led many project managers to defer upgrades at all costs. This policy isn't justified, though. Almost without exception, these changes are only for the best.

Danny Kalev is a certified system analyst and software engineer specializing in C++ and the theoretical aspects of formal languages. He is the author of Informit C++ Reference Guide and The ANSI/ISO Professional C++ Programmer's Handbook. He was a member of the C++ standards committee between 1997 and 2000. Danny recently finished his MA in general linguistics summa cum laude. In his spare time he likes to listen to classical music, read Victorian literature, and explore natural languages such as Hittite, Basque, and Irish Gaelic. Additional interests include archeology and geology. He also gives lectures about programming languages and applied linguistics at academic institutes.


引自:http://www.devx.com/cplus/10MinuteSolution/28908/0/page/1


-------------------------------------------------------------------------------------------------------------------

VC6==>VS2005的一些問題

我接收到一個任務,是把公司的一個產品從vc6遷移到vs2005,結果發現了很多的warning和error

warning 主要是使用了strcpy,strcat這樣的函數
這些在2005中都是unsafe_api.
在vs2005都推薦使用strcpy_s,strcat_s.
我想微軟這么做固然跟C++ standard有偏差
但是這些函數的使用確實造成了微軟產品經常有的漏洞
微軟深受這些函數的危害阿
所以在vs2005這些都是warning

error的類型主要是以下幾種,多半和STL有關

1.include 帶.h的舊式頭文件,比如 #include <iostream.h>改為include <iostream>

2.vc6的string iterator的 char *,而vs2005中卻不是
strcpy(s.begin(), str);是不能compile的,應改為strcpy((char *) s.c_str(),str);

3.函數返回類型不支持缺省是int
missing type specifier - int assumed. Note: C++ does not support default-int
<Code>
    extern IsWindowsNT();

<Fix>
    extern int IsWindowsNT();

posted on 2005-12-20 08:56 夢在天涯 閱讀(2081) 評論(1)  編輯 收藏 引用 所屬分類: CPlusPlus

評論

# re: 移置c++從6.0到2005 2010-02-09 16:25 wantukang

不錯,先記下,以后有需要再來查看  回復  更多評論   

公告

EMail:itech001#126.com

導航

統計

  • 隨筆 - 461
  • 文章 - 4
  • 評論 - 746
  • 引用 - 0

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1811726
  • 排名 - 5

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              久久精品国语| 欧美电影免费观看高清| 欧美在线视频a| 黄色成人在线观看| 欧美成人一二三| 中文av字幕一区| 久久久久久网址| 9久草视频在线视频精品| 欧美日韩精品在线观看| 欧美在线免费| 夜夜爽www精品| 蜜臀久久99精品久久久久久9| 亚洲日本免费| 激情欧美日韩| 国产精品久久久久久久久免费桃花 | 午夜视频一区二区| 亚洲国产精品电影| 久久久久www| 亚洲深夜福利在线| 91久久一区二区| 国产欧美视频一区二区| 欧美高清在线视频| 葵司免费一区二区三区四区五区| 亚洲裸体在线观看| 亚洲国产婷婷| 欧美黄色aaaa| 欧美成人精品在线观看| 久久综合伊人77777麻豆| 欧美一级理论片| 欧美影院午夜播放| 午夜精品久久久| 欧美中日韩免费视频| 亚洲午夜小视频| 亚洲欧美国产77777| 中国成人黄色视屏| 亚洲欧美日本另类| 久久久久久久97| 老色鬼久久亚洲一区二区| 欧美**字幕| 亚洲另类自拍| 亚洲欧美国产高清| 久久精品国产91精品亚洲| 亚洲国产成人精品女人久久久| 欧美在线亚洲综合一区| 亚洲欧美日韩国产一区| 欧美中文在线观看国产| 久久亚洲一区二区| 最近中文字幕日韩精品| 亚洲国产精品久久久久秋霞蜜臀| 久久久久久网址| 亚洲精品之草原avav久久| 中文高清一区| 欧美国产日韩亚洲一区| 国产精品少妇自拍| 久久久久久夜| 亚洲高清视频的网址| 日韩一级网站| 久久久五月天| 国产欧美精品日韩精品| 亚洲美女性视频| 欧美暴力喷水在线| 免费观看30秒视频久久| 亚洲国产日韩综合一区| 欧美亚洲网站| 亚洲精品小视频| 免费在线一区二区| 亚洲激情成人| 欧美高清一区| 久久成人免费日本黄色| 国产亚洲成av人在线观看导航| 亚洲无线观看| 在线综合亚洲| 国产精品―色哟哟| 久热精品视频在线观看| 久久精品91久久香蕉加勒比| 黑人极品videos精品欧美裸| 久久久久久久精| 久久亚洲精品欧美| 亚洲巨乳在线| 亚洲一二三区视频在线观看| 国产欧美一区二区精品婷婷| 欧美一区二区免费| 久久亚洲精品视频| 99热在线精品观看| 性久久久久久久久| 最新高清无码专区| 亚洲欧美成人一区二区三区| 国产专区精品视频| 亚洲精品国产精品乱码不99 | 中文在线资源观看网站视频免费不卡 | 亚洲欧洲日本专区| 亚洲欧洲一区| 国产精品一区二区三区四区五区| 日韩视频在线观看| 99精品99| 亚洲第一级黄色片| 一区二区高清视频在线观看| 极品尤物一区二区三区| 一区二区日韩欧美| 在线不卡a资源高清| 亚洲伦理在线免费看| 国产一区91精品张津瑜| 亚洲最新视频在线| 伊人久久成人| 久久久久久久999| 久久精品国产91精品亚洲| 欧美精品在线免费观看| 免费成人性网站| 国内精品99| 亚洲欧美日韩精品一区二区| 亚洲精品久久久一区二区三区| 亚洲欧美在线一区| 欧美淫片网站| 国产视频观看一区| 在线一区二区三区四区五区| 99国产精品自拍| 男女av一区三区二区色多| 蜜桃av综合| 亚洲国产毛片完整版 | 欧美日韩中国免费专区在线看| 蜜桃av久久久亚洲精品| 国产精品永久免费视频| 亚洲欧美怡红院| 狂野欧美激情性xxxx欧美| 国产一区在线播放| 99国产麻豆精品| 国产精品美腿一区在线看| 亚洲一区二区免费视频| 欧美在线二区| 在线播放亚洲| 欧美日产一区二区三区在线观看| 亚洲免费观看视频| 久久综合给合| 亚洲免费一在线| 亚洲国产欧美日韩| 国产精品人人爽人人做我的可爱| 久久久国产成人精品| 亚洲人成久久| 久久天堂国产精品| 欧美在线观看一区二区| 在线免费高清一区二区三区| 欧美四级在线| 欧美成人在线免费观看| 亚洲一区二区三区在线| 亚洲国产岛国毛片在线| 久久偷看各类wc女厕嘘嘘偷窃| 亚洲影院一区| 亚洲欧美日韩第一区| 亚洲精品亚洲人成人网| 激情欧美一区二区| 国产欧美日韩一级| 国产精品视频免费| 国产日产欧美精品| 国产精品久久久久av免费| 久久综合色天天久久综合图片| 中文一区二区| av成人免费观看| 亚洲精选91| 亚洲一区二区三区在线视频| 这里只有精品丝袜| 一本大道久久a久久精品综合| 亚洲激情在线播放| 欧美粗暴jizz性欧美20| 欧美成人69av| 亚洲免费av网站| 亚洲一区三区视频在线观看| 中文在线一区| 久久成人18免费网站| 久久久国产一区二区三区| 免费亚洲网站| 国产精品久久久久9999| 国产伊人精品| 日韩一级精品视频在线观看| 亚洲综合欧美日韩| 久久亚洲国产精品日日av夜夜| 亚洲国产电影| 久久不见久久见免费视频1| 欧美—级在线免费片| 国模私拍视频一区| 亚洲天堂av高清| 欧美韩国日本综合| 欧美在线免费| 国产美女精品视频| 99热免费精品| 欧美不卡视频一区发布| 香蕉av777xxx色综合一区| 女人色偷偷aa久久天堂| 国产欧美69| 亚洲性人人天天夜夜摸| 欧美激情第4页| 久久精品人人做人人综合| 国产精品久久久久一区二区| 一本色道久久综合狠狠躁篇怎么玩| 亚洲第一搞黄网站| 久久人人九九| 欧美亚洲一区| 欧美日韩一区二区三区免费| 亚洲精品一区二区三区四区高清| 欧美成人综合网站| 欧美成年人网|