`

Exception C++ Style Chapter32

阅读更多
 
#include <iostream>
#include <iomanip>

int main()
{
        int x=1;
        for(int i=0;i<100;++i){
            // 下面这段代码会干什么?递增?????????????????????????/
            ++x;
            std::cout<<x<<std::endl;
        }

        std::cout<<"____??/n_____"<<std::endl;

        return 0;
}

 

Gnu g++文档说:对注释中的三字符组不会发出编译警告,因为他们不会对程序的意义产生影响。上述的例子便说明并非如此。

 

但书中描述的问题,在GNU g++中貌似已经不存在,。但问题是为什么对后面的那个cout中的"??/"也没有给转译成"\"呢?

 

MS c++ 8中test倒是看到了书中描述的问题,注意这个这个陷阱“行尾的/”

 

而且按照c++标准,除了注释中,是不允许出现笑脸符号(:>)的,:>会被转译成],这致使a[i:>等效于a[i],但是貌 似ms vc与gnu g++这两种编译器都不支持对这个他的转移,这倒说不定是件好事,通常我们写成这样的代码都是因为拼写错误。

 

从上面的分析看是G++默认没有打开对三字组的支持,微软开了对他的支持,但不支持对:>的转译。

分享到:
评论

相关推荐

    Addison.Wesley.C++.by.Dissection.2002.pdf

    This chapter introduces the reader to the fundamentals of writing a C++ program. It covers: - **Getting Ready to Program:** Discusses the setup required to write and run C++ programs. - **A First ...

    C++ Standard Library: A Tutorial and Reference

    General Concepts &lt;br/&gt;3.1 Namespace &lt;br/&gt;3.2 Header Files &lt;br/&gt;3.3 Error and Exception Handling &lt;br/&gt;3.4 Allocators &lt;br/&gt;Chapter 4. Utilities &lt;br/&gt;4.1 Pairs &lt;br/&gt;4.1.1 ...

    Professional.MFC.with.VC6

    Win32 Structured Exception Handling Collection Classes The Type-safe Collection Classes Lists Arrays Maps Another Path to Type Safety Files CFile CStdioFile CMemFile MFC and File Security ...

    Professional C# 3rd Edition

    Chapter 1: .NET Architecture 3 The Relationship of C# to .NET 4 The Common Language Runtime 4 Advantages of Managed Code 4 A Closer Look at Intermediate Language 7 Support for Object Orientation and ...

    Python Cookbook, 2nd Edition

    Using a C++-like iostream Syntax Recipe 2.14. Rewinding an Input File to the Beginning Recipe 2.15. Adapting a File-like Object to a True File Object Recipe 2.16. Walking Directory Trees ...

Global site tag (gtag.js) - Google Analytics