Ansi C和C ++之间的主要区别 [英] Key Differences Between Ansi C and C++

查看:90
本文介绍了Ansi C和C ++之间的主要区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为C ++程序员教授一门C程序设计课程,并希望

提出两种语言之间的_KEY_差异列表。

下面是我的列表到目前为止提出来了。我错过了吗?


ANSI C和C ++之间的主要差异


1. C是一种过程编程语言(C ++是一种对象

面向对象的编程语言)。这意味着C编程

语言不支持类和所有功能直接或间接通过类提供的
。因此C不支持

继承,多态或数据封装。 C确实支持

struct,这类似于不支持成员函数的类

并且无法封装定义的数据成员

属于struct(struct是ADT)。


2. C无法访问iostream库。输入和输出

C使用stdio.h库完成,该库提供对

scanf()和printf()函数的访问,用于输入和输出<分别为



3. C不支持异常处理。


4. C不支持模板。


5. C不支持名称空间。


6. C不支持引用。


7. C不支持默认参数值。


8. C不支持重载函数名称。


9. C表示不允许你在for语句中声明变量

标题(但是C99会这样做!)。


10.C要求块范围的所有变量都必须在块的开头声明

(不是C99的情况!)。


11. C不支持new和delete运算符。动态

变量是使用malloc()和free()函数创建的,以及

作为calloc()和realloc()函数。


12. C不支持四个C ++强制转换运算符static_cast,
dynamic_cast,const_cast和reinterpret_cast。必须使用C风格进行所有演员表演

。演员。


13. C不支持内联函数(但C99会支持!)。


14. C不支持一元范围运算符。


15. C不支持//发表评论(但C99确实如此!)。


16. C包括C库的文件名通常不同于C +

+包含相同库的文件名,即使它们包含相同C函数的原型
原型。通常你删除前导

''c''并附加.h到文件名的末尾。例如,C ++

< cstdioinclude文件是< stdio.hin C; C ++< cstdlibinclude

文件是< stdlib.hin C; C ++< ctimeinclude文件是< time.h>

in C.


17. C不支持bool和long long类型(但是C99会这样做!)。

I am teaching a C programming course to C++ programmers and want to
come up with list of _KEY_ differences between the two languages.
Below is a list I have come up with so far. Have I missed any?

Key Differences between ANSI C and C++

1. C is a procedural programming language (where as C++ is an Object
Oriented Programming language). This means that the C programming
language does not support classes and all functionality provided
directly or indirectly through classes. Therefore C does not support
inheritance, polymorphism or encapsulation of data. C does support
"struct"s, which are like classes without support for member functions
and with no ability to encapsulate the data members that are defined
as belonging to the struct (a struct is an ADT).

2. C does not have access to the iostream library. Input and output in
C is done using the stdio.h library which provides access to the
scanf() and printf() functions, used to do input and output
respectively.

3. C does not support exception handling.

4. C does not support templates.

5. C does not support namespaces.

6. C does not support references.

7. C does not support default parameter values.

8. C does not support overloaded function names.

9. C does not allow you to declare a variable in a for statement
header (but C99 does!).

10. C requires that all variables of block scope must be declared at
the beginning of the block (not the case with C99!).

11. C does not support the new and delete operators. Dynamic
variables are created using the malloc() and free() functions, as well
as the calloc() and realloc() functions.

12. C does not support the four C++ cast operators static_cast,
dynamic_cast, const_cast and reinterpret_cast. All casts must be done
using the "C-style" cast operator.

13. C does not support inline functions (but C99 does!).

14. C does not support the unary scope operator.

15. C does not support // to start a comment (but C99 does!).

16. C include file names for C libraries are usually different than C+
+ include file names for the same libraries, even though they contain
prototypes for the same C functions. Generally you remove the leading
''c'' and append ".h" to the end of the file name. For example the C++
<cstdioinclude file is <stdio.hin C; the C++ <cstdlibinclude
file is <stdlib.hin C; and the C++ <ctimeinclude file is <time.h>
in C.

17. C does not support the types bool and long long (but C99 does!).

推荐答案

blangela写道:
blangela wrote:

我正在为C ++程序员教授一门C程序设计课程,并希望

得出两种语言之间的_KEY_差异列表。

下面是我提出的列表至今。我错过了吗?


ANSI C和C ++之间的主要差异


1. C是一种过程编程语言(C ++是一种对象

面向对象的编程语言)。这意味着C编程

语言不支持类和所有功能直接或间接通过类提供的
。因此C不支持

继承,多态或数据封装。 C确实支持

struct,这类似于不支持成员函数的类

并且无法封装定义的数据成员

属于struct(struct是ADT)。
I am teaching a C programming course to C++ programmers and want to
come up with list of _KEY_ differences between the two languages.
Below is a list I have come up with so far. Have I missed any?

Key Differences between ANSI C and C++

1. C is a procedural programming language (where as C++ is an Object
Oriented Programming language). This means that the C programming
language does not support classes and all functionality provided
directly or indirectly through classes. Therefore C does not support
inheritance, polymorphism or encapsulation of data. C does support
"struct"s, which are like classes without support for member functions
and with no ability to encapsulate the data members that are defined
as belonging to the struct (a struct is an ADT).



C ++有时被称为多范式语言,这意味着它支持许多样式的编程,包括面向对象(尽管没有两种)

人们就这意味着什么,程序和其他人达成一致。


C可以支持继承,多态,甚至数据封装,它

只是语言没有考虑到这些,所以支持这些东西所需的

结构在C语言中比在C ++中更笨拙。


按ADT我猜你的意思是抽象数据类型。如果是这样那么一个结构是最好的

绝对不是一个抽象的数据类型,而一个精心设计的类是。

C++ is sometimes called a multi-paradigm language, meaning it supports
many styles of programming, including object-orientated (although no two
people ever agree on what that means), procedural, and others.

C can support inheritance, polymorphism and even data encapsulation, it
just that the language was not designed with these in mind, and so the
constructs needed to support these things are more awkward in C than in C++.

By ADT I guess you mean abstract data type. If so then a struct is most
definitely not an abstract data type, whereas a well designed class is.


>

2. C无法访问iostream库。输入和输出

C使用stdio.h库完成,该库提供对

scanf()和printf()函数的访问,用于输入和输出<分别为



3. C不支持异常处理。


4. C不支持模板。


5. C不支持名称空间。


6. C不支持引用。


7. C不支持默认参数值。


8. C不支持重载函数名称。
>
2. C does not have access to the iostream library. Input and output in
C is done using the stdio.h library which provides access to the
scanf() and printf() functions, used to do input and output
respectively.

3. C does not support exception handling.

4. C does not support templates.

5. C does not support namespaces.

6. C does not support references.

7. C does not support default parameter values.

8. C does not support overloaded function names.



或重载运算符。

Or overloaded operators.


>

9. C表示不允许你在for语句中声明变量

标题(但是C99会这样做!)。


10.C要求块范围的所有变量都必须在块的开头声明

(不是C99的情况!)。


11. C不支持new和delete运算符。动态

变量是使用malloc()和free()函数创建的,以及

作为calloc()和realloc()函数。
>
9. C does not allow you to declare a variable in a for statement
header (but C99 does!).

10. C requires that all variables of block scope must be declared at
the beginning of the block (not the case with C99!).

11. C does not support the new and delete operators. Dynamic
variables are created using the malloc() and free() functions, as well
as the calloc() and realloc() functions.



动态变量是不正确的terminolgy,动态分配的内存

更好。


另外值得注意到C99支持动态数组,即


int n = something();

int array [n];


这不是合法的C ++。

Dynamic variables is incorrect terminolgy, dynamically allocated memory
is better.

Also worth noting that C99 supports dynamic arrays, i.e.

int n = something();
int array[n];

which is not legal C++.


>

12. C不支持四个C ++强制转换运算符static_cast,

dynamic_cast,const_cast和reinterpret_cast。必须使用C风格进行所有演员表演

。演员。


13. C不支持内联函数(但C99会支持!)。


14. C不支持一元范围运营商。
>
12. C does not support the four C++ cast operators static_cast,
dynamic_cast, const_cast and reinterpret_cast. All casts must be done
using the "C-style" cast operator.

13. C does not support inline functions (but C99 does!).

14. C does not support the unary scope operator.



好​​吧,它没有必要。

Well, it has no need for it.


>

15. C不支持//开始评论(但是C99确实如此!)。


16. C包含C库的文件名通常与C +不同

+包含相同库的文件名,即使它们包含相同C函数的原型
原型。通常你删除前导

''c''并附加.h到文件名的末尾。例如,C ++

< cstdioinclude文件是< stdio.hin C; C ++< cstdlibinclude

文件是< stdlib.hin C;并且C ++< ctimeinclude文件是< time.h>

in C.
>
15. C does not support // to start a comment (but C99 does!).

16. C include file names for C libraries are usually different than C+
+ include file names for the same libraries, even though they contain
prototypes for the same C functions. Generally you remove the leading
''c'' and append ".h" to the end of the file name. For example the C++
<cstdioinclude file is <stdio.hin C; the C++ <cstdlibinclude
file is <stdlib.hin C; and the C++ <ctimeinclude file is <time.h>
in C.



C ++还支持C include文件名。

C++ also supports the C include file names.


>

17. C不支持bool和long long类型(但C99会支持!)。
>
17. C does not support the types bool and long long (but C99 does!).



C也不支持wchar_t类型作为一种独特的类型(它是C中的
typedef)。


明确没有出现在列表中的两件重要事情是构造函数和析构函数的

概念。特别是析构函数是C ++的关键特性之一。没有其他常用语言有我知道的
析构函数。


C ++也有typeid运算符和typeinfo类。


看起来像一个非常完整的功能列表,但我认为关键

的区别在于两种语言被主管使用的风格

程序员。我认为C ++通常被编程为更多的思考

给予设计问题,C更加自由和简单。


john

C also does not support the wchar_t type as a distinct type (it''s a
typedef in C).

Two important things that are not in your list explicitly, are the
concepts of constructors and destructors. Destructors in particular are
one of C++''s key features. No other commonly used language has
destructors that I am aware of.

C++ also has the typeid operator and the typeinfo class.

Seems like a pretty complete list of features, but I think the key
difference is the style in which the two languages are used by competent
programmers. I think C++ is generally programmed with much more thought
given to design issues, C is much more free and easy.

john


blangela写道:
blangela wrote:

我正在为C ++程序员教授一门C程序设计课程并希望

来两种语言之间的_KEY_差异列表。

下面是我到目前为止提出的列表。我错过了吗?
I am teaching a C programming course to C++ programmers and want to
come up with list of _KEY_ differences between the two languages.
Below is a list I have come up with so far. Have I missed any?





http://david.tribble.com/text/cdiffs.htm


之间的主要差异ANSI C和C ++


1. C是一种过程编程语言(其中C ++是一种对象

面向编程语言)。
Key Differences between ANSI C and C++

1. C is a procedural programming language (where as C++ is an Object
Oriented Programming language).



C ++是一种多范式语言。


-

Ian Collins。

C++ is a multi-paradigm language.

--
Ian Collins.


(消息(你好''blangela)

(你:写道:'''(2007年3月3日12:00:34 -0800) )




加入_KEY_差异列表两种语言之间的比较。

bBelow是我到目前为止提出的一个列表。我错过了吗?


imho重要区别之一是C ++有更严格的转换

规则。

即C允许从void *转换为任何指针类型,而C ++
不会。


当尝试使用C ++编译C源文件时会导致问题

编译器。

(我记得有些编译器来自诺基亚Symbian SDK根本没有C模式,

因此我必须修复转换以使用C ++编译器编译C文件。)




(最好问候''(Alex Mizrahi):又名''killer_storm)

" ?? ???? ??????? ?????
(message (Hello ''blangela)
(you :wrote :on ''(3 Mar 2007 12:00:34 -0800))
(

bI am teaching a C programming course to C++ programmers and want to
bcome up with list of _KEY_ differences between the two languages.
bBelow is a list I have come up with so far. Have I missed any?

imho one of important differences is that C++ has more strict conversion
rules.
i.e. C will allow conversion from void* to any pointer type, while C++
won''t.

this can lead to problems when trying to compile C source file with C++
compiler.
(i remember some compiler from Nokia Symbian SDK did not have C mode at all,
so i had to fix conversions to compile C files with C++ compiler).

)
(With-best-regards ''(Alex Mizrahi) :aka ''killer_storm)
"?? ???? ??????? ?????")


这篇关于Ansi C和C ++之间的主要区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆