C Reference Manual Reading Notes: 007 C++ Compatibility

本文探讨了C语言与C++在字符集、注释、运算符、标识符及关键字、字符常量等方面的主要区别。重点介绍了两种语言中特有的元素及其对程序移植性的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Character Sets

    The token respelling and trigraphs in Standard C are part of the C++ Standard, but they are not common in pre-Standard C++ implementations. Boths C and C++ allow universal character names with same syntax, but only C explicitly allows other implementation-defined character in identifiers. (One expects that C++ implementations will provide them as an extension.)

 

2. Comments

    C99 comments are acceptable as C++ and vice versa.  Before C99, the characters //  did not introduce a comment in Standard C, and so the sequence of character //* in C could be interpreted differently in C++.

 

3. Operators

    There are three new compound operators in C++:

           .*    ->*    ::

    Since these combinations of tokens would be invalid in Standard C programs, there is no impact on portability from C to C++.

 

4. Identifiers and Keywords

    The identiofiers listed in latter are keywords in C++, but not in C. However, the keyword wchar_t is reserved in Standard C, and the keywords bool, true and false are reserved in C99 as part of the standard libraries.

          asm                   export            private                       throw

          bool                   false               protected                  true

          catch                 friends            public                         try

          class                  mutable          reinterpret_case        typeid

          const_cast         namespace    static_cast                 typename

          delete                new                template                    using

          dynamic_cast    operator          this                            virtual

          explicit                                                                        wchar_t

 

5. Character Constants

    Single-character constants have type int in C, but have type in C++. Multicharacter constants-which are implementation-defined--have type int in both languages. In practice, this makes little difference since in C++ character constants used in integral contexts are promoted to int under the usual conversions. However, sizeof('C') is sizeof(char) in C++, whereas it is sizeof(int) in C.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值