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

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 夢在天涯 閱讀(2094) 評論(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

搜索

  •  

積分與排名

  • 積分 - 1817698
  • 排名 - 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>
              另类欧美日韩国产在线| 午夜一区二区三区在线观看| 浪潮色综合久久天堂| 狠狠色狠狠色综合日日五| 欧美在线999| 久久激五月天综合精品| 依依成人综合视频| 亚洲大胆女人| 欧美激情精品久久久久久黑人| 亚洲日本一区二区三区| 99国产精品久久久久久久| 国产精品欧美久久| 久久久精品动漫| 蜜桃av噜噜一区二区三区| 亚洲国产日韩欧美在线图片| 亚洲国产成人不卡| 国产精品理论片在线观看| 久久久久99| 欧美电影在线观看| 午夜精品在线看| 久久资源在线| 亚洲视频狠狠| 久久久www免费人成黑人精品| 最新亚洲视频| 午夜天堂精品久久久久| 亚洲精品美女在线观看播放| 亚洲性av在线| 最新日韩在线| 午夜影院日韩| 在线亚洲国产精品网站| 久久精精品视频| 亚洲一区二区三区四区在线观看| 久久精品国产99国产精品| 亚洲免费观看在线观看| 久久国产精品黑丝| 亚洲一区二区三区精品在线观看| 欧美中文字幕精品| 亚洲综合首页| 免费av成人在线| 久久av老司机精品网站导航| 欧美激情第1页| 久久影院午夜片一区| 欧美午夜不卡在线观看免费 | 日韩一区二区福利| 欧美一区在线视频| 亚洲综合首页| 欧美日韩亚洲综合在线| 欧美成人一区在线| 国产中文一区二区| 亚洲性视频网站| 一区二区三区成人精品| 麻豆精品在线视频| 久久综合久久综合久久| 久久av资源网站| 亚洲美女网站| 欧美亚洲在线视频| 亚洲私人影院在线观看| 欧美大学生性色视频| 六月丁香综合| 国产专区欧美专区| 欧美一区二区视频观看视频| 亚洲欧美激情一区| 国产精品不卡在线| 亚洲私人黄色宅男| 亚洲综合99| 欧美一区二区三区视频| 亚洲伊人一本大道中文字幕| 欧美激情在线狂野欧美精品| 亚洲国产国产亚洲一二三| 在线视频国内自拍亚洲视频| 久久久久久久久久久久久久一区| 欧美在线亚洲一区| 国产一区二区三区无遮挡| 欧美一区二区三区喷汁尤物| 久久嫩草精品久久久久| 韩国女主播一区| 久久人人爽国产| 欧美激情一区二区三区全黄 | 久久久久久九九九九| 老色鬼精品视频在线观看播放| 国产专区欧美精品| 麻豆国产精品一区二区三区| 亚洲国产激情| 国产精品99久久不卡二区 | 欧美主播一区二区三区| 久久久91精品国产一区二区三区| 国精品一区二区三区| 蜜臀99久久精品久久久久久软件| 亚洲黄色高清| 亚洲一区观看| 国产一区二区高清视频| 蜜臀va亚洲va欧美va天堂| 亚洲精品综合精品自拍| 欧美在线视频一区二区| 亚洲福利在线视频| 国产精品v欧美精品∨日韩| 亚洲免费视频网站| 女人色偷偷aa久久天堂| av成人手机在线| 国产性做久久久久久| 欧美成人午夜免费视在线看片| 一区二区三区四区五区在线| 久久久福利视频| 一二三四社区欧美黄| 国产一区在线看| 欧美精品在线观看一区二区| 香蕉av777xxx色综合一区| 亚洲国产精品尤物yw在线观看 | 国产乱子伦一区二区三区国色天香| 久久九九全国免费精品观看| 亚洲精品欧美激情| 老司机一区二区三区| 亚洲一区影音先锋| 最新精品在线| 国产三区二区一区久久| 欧美日韩不卡视频| 久久久精品国产免费观看同学| 日韩亚洲视频| 亚洲国产成人午夜在线一区| 久久精品人人做人人爽电影蜜月| 99精品国产高清一区二区 | 欧美破处大片在线视频| 欧美一区二区三区精品| aa级大片欧美| 欧美华人在线视频| 久久在线免费| 久久久久久9| 午夜精品成人在线视频| av成人国产| 亚洲精品一二区| 亚洲福利精品| 亚洲成人资源网| 精品电影在线观看| 国内精品一区二区三区| 国产欧美日韩一区| 国产精一区二区三区| 欧美性事在线| 欧美性一二三区| 欧美日韩亚洲高清一区二区| 欧美电影在线观看| 欧美成人首页| 欧美激情一区二区三区在线视频 | 性欧美xxxx视频在线观看| 国产精品99久久久久久久久| 亚洲三级免费| 日韩午夜中文字幕| 99这里只有久久精品视频| 亚洲精品日韩综合观看成人91| 亚洲国产美女| 亚洲人午夜精品| 日韩一级精品视频在线观看| 日韩午夜在线视频| 中文无字幕一区二区三区| 亚洲一区在线视频| 欧美一区二区三区在线观看视频| 亚洲欧美制服另类日韩| 欧美在线电影| 免费成人高清视频| 欧美人成网站| 国产精品美女久久久久久免费| 国产精品有限公司| 在线观看一区| 一区二区三区久久久| 亚洲少妇诱惑| 久久精品动漫| 欧美成人在线影院| 亚洲免费观看高清完整版在线观看熊 | 日韩亚洲欧美精品| 日韩视频国产视频| 亚洲综合不卡| 亚洲在线观看视频网站| 久久国产婷婷国产香蕉| 欧美1区2区3区| 99精品热视频| 欧美一级网站| 欧美成人黑人xx视频免费观看| 欧美日韩国产小视频| 国产免费亚洲高清| 亚洲国产精品电影| 亚洲欧美另类在线观看| 久久在线精品| 一区二区日本视频| 久久久久久久久综合| 欧美三级日本三级少妇99| 国产综合色产在线精品| 99亚洲视频| 美女久久一区| 亚洲影音一区| 欧美激情第4页| 国产一区二区黄| 亚洲婷婷在线| 欧美激情精品久久久| 亚洲男人影院| 欧美日韩一二三四五区| 黄色精品网站| 香蕉国产精品偷在线观看不卡| 欧美黄色aa电影| 久久se精品一区精品二区| 国产精品卡一卡二| 夜夜嗨av色一区二区不卡|