Is C/C++ one language or two languages? I heard C++ was just C with classes. Is that right?
C/ c++是一种语言还是两种语言?我听说c++只是带类的C。是这样吗?
9 个解决方案
#1
66
C++ diverged from C in 1982-1983, and that's a long time in computer years. But, there are many C libraries with C++ compatibility, including the C standard library itself, and a steady stream of programs are ported across from C to C++. Many C programmers only know or use the features that are compatible with C++.
从1982年到1983年,c++偏离了C,这在计算机时代是很长的一段时间。但是,有许多具有c++兼容性的C库,包括C标准库本身,并且有稳定的程序流从C移植到c++。许多C程序员只知道或使用与c++兼容的特性。
They are defined by different ISO standards from separate committees. Even when they define compatible features, it is often defined in different terms.
它们由不同的ISO标准和不同的委员会定义。即使它们定义了兼容的特性,也常常用不同的术语来定义。
Referring to C/C++ is about as valid as referring to Italian/Spanish. You should be careful to whom and when you use such a term. But it's true that there is diffusion of ideas in both directions, and the similarities are more than coincidence.
C/ c++和意大利语/西班牙语一样有效。当你使用这个词时,你应该小心。但确实,思想在两个方向上都有传播,而且相似之处不仅仅是巧合。
#2
33
"C/C++" is precisely zero languages. It does not exist.
“C/ c++”正是零语言。它不存在。
On the other hand, C is a language.
另一方面,C是一种语言。
C++ is another language, which is kind of like C but also has classes and lots of other differences.
c++是另一种语言,它有点像C语言,但也有类和很多其他的区别。
To be clear, @Zoidberg was spot on:
需要澄清的是,@Zoidberg是:
C and C++ are two completely different languages. C with Classes was the predecessor of C++, but the term is still often used for non-modern C++ (e.g. that uses raw pointers all over the place).
C和c++是两种完全不同的语言。带类的C是c++的前身,但是这个术语仍然经常用于非现代的c++(例如,到处都使用原始指针)。
#3
23
It is two languages. Calling C++ "C with classes" is like calling an elephant a four legged animal. It seems true till you compare it to a mouse.
这是两种语言。把c++称为“带类的C”就像把大象叫做四条腿的动物。直到你把它比作鼠标,它才显得真实。
There are many languages which derive from C: C++, Java, C#, JavaScript, csh, the list goes on. They are all different in many ways but they share similar syntax.
有许多语言源自C: c++, Java, c#, JavaScript, csh,等等。它们在很多方面都不同,但是它们有相似的语法。
Of course C derived from B. But that is another story (and no one cares about B anymore.)
C当然是从B衍生而来的,但那是另一个故事(没有人再关心B了)。
#4
12
Simple answer: two languages
答案很简单:两种语言
They are two different languages, although almost any C code is valid (not necessarily good) C++ code.
它们是两种不同的语言,尽管几乎所有的C代码都是有效的(不一定是好的)c++代码。
C++ was at first thought about as "C, but with classes", but as the time passed, it differed more and more and now C code is very bad C++ code. You can learn C or C++ or both, but you usually don't mix them up (but you can).
c++最初被认为是“C,但是有类”,但是随着时间的推移,它变得越来越不同,现在C代码是非常糟糕的c++代码。你可以学习C或c++或两者,但你通常不会混淆它们(但你可以)。
#5
4
C/C++ is two languages. C is one language, and C++ is the other. C++ is considered a 'better' C. C is procedural, whereas C++ is object oriented. C++ has a lot of improvements over C, and has a similar syntax to C.
C / c++是两种语言。C是一种语言,c++是另一种语言。c++被认为是“更好的”C C是程序化的,而c++是面向对象的。与C相比,c++有很多改进,语法与C类似。
#6
4
They are two different languages. C++ is so named because part of it is rooted from C and compatible with C in some sense.
它们是两种不同的语言。c++之所以如此命名,是因为它的一部分源自C,在某种意义上与C兼容。
According to Scott Myers's Effective C++, we can view C++ as a unified language with the following 4 components:
根据Scott Myers有效的c++,我们可以将c++看作一种统一的语言,它包含以下4个部分:
- C language part, blocks, statements, preprocessor, etc
- C语言部分,块,语句,预处理器等
- Objected Oriented C++: including class, encapsulation, inheritance, polymorphism, etc
- 面向对象的c++:包括类、封装、继承、多态性等。
- Template C++: including C++ templates, metaprogramming stuff
- 模板c++:包括c++模板,元编程
- The STL.
- STL。
So C++ is more powerful than C in some sense.
所以c++在某种意义上比C更强大。
#7
1
The name "C" refers to a family of related languages, some of which are formalized as international standards. These include K&R C, ANSI C, C99, and C11.
“C”一词是指一系列相关语言,其中一些被正式定为国际标准。包括K&R C、ANSI C、C99和C11。
The name "C++" refers to a family of related languages, some of which are formalized as international standards. These include C++98, C++03, C++11, C++14, and the speculated C++17.
“c++”一词是指一系列相关语言,其中一些被正式定义为国际标准。其中包括c++ 98, c++ 03, c++ 11, c++ 14,以及推测的c++ 17。
The term "C/C++" is used by many people to informally refer to the intersection of C and C++, which has been intentionally maintained by the designers of C++.
“C/ c++”一词被许多人用来非正式地引用C和c++的交集,这是c++设计者故意维护的。
C++'s immediate predecessor was in fact originally called "C with Classes". This is detailed in Bjarne Stroustrup's 1994 book "The Design and Evolution of C++" (and also here). The name was eventually changed to "C++", largely as a courtesy to the C community because it had become too tempting for people to shorten "C with Classes" to just "C" or "new C".
c++的直接前身实际上最初被称为“类”。这在Bjarne Stroustrup 1994年的书《c++的设计与进化》(也在这里)中有详细的描述。这个名字最终被改成了“c++”,这主要是对C社区的一种礼遇,因为人们很容易将“C with Classes”缩写为“C”或“new C”。
There are many language features in C++ that are not in C (the reverse is true to a lesser extent). In particular, the class-based model, due to its capability to invoke implicit function calls, is so powerful that C++ has (rather organically) evolved higher-level programming styles that make the typical usage of C++ much different than that of C. The most notable examples of this are associated with the concept called Resource Acquisition Is Initialization, which is embodied in the standard classes string, vector, and shared_ptr as well as the stream classes of the standard I/O library.
c++中有许多语言特性不在C语言中(相反的情况在较小程度上是正确的)。特别是,基于类的模型,由于其能力来调用隐函数调用,是如此的强大,c++(而不是有机)的进化而来的高级编程风格,使c++完全不同的典型用法比C最引人注目的例子是相关的概念叫做资源获取初始化,这是体现在标准类字符串,向量,要查看以及流类标准I / O库。
Other notes:
另注:
-
GCC allows you to specify which of these language variations you want to compile against (as do other compilers, I'm sure), with some limitations.
GCC允许您指定要编译的这些语言变体中的哪一种(我确信其他编译器也是如此),但有一些限制。
-
C++98 and C++03 have minimal feature differences and are often treated as essentially the same language.
c++ 98和c++ 03具有最小的特性差异,通常被视为本质上相同的语言。
-
Top questions that address the common subset of C and C++:
解决C和c++的公共子集的最重要的问题:
- In C++ source, what is the effect of extern "C"?
- 在c++源代码中,outside的作用是什么?
- Where is C not a subset of C++?
- C不是c++的子集吗?
#8
1
IMHO, I think the answer is that C/C++ are not one language, but two which are:
我认为答案是C/ c++不是一种语言,而是两种语言:
- C Programming language
- C编程语言
- C++ Programming language
- c++编程语言
The C++ language is derived from the C language. C++ is the name for the C programming language with added 'classes' functionality. That means that the basic C language architecture has been enhanced to allow object oriented programming. It uses the "++" operator that means increment. C++ is an increment of C, which allows you to use procedural way or object oriented way or both of them in programming ways. C++ allows us to write code easier than C. But this does not mean that the C language is not suitable now, because we have C++. Each language is used for goal the purpose of software that is needed by a programmer. That's why ANSI made C a standard.
c++语言源自C语言。c++是添加了“类”功能的C编程语言的名称。这意味着基本的C语言体系结构得到了增强,允许面向对象编程。它使用“++”运算符表示增量。c++是C的一个增量,它允许您使用过程方式或面向对象方式,或者在编程方式中同时使用它们。c++允许我们编写比C更容易的代码,但这并不意味着C语言现在不合适,因为我们有c++。每一种语言都是为了实现程序员所需要的软件目的而使用的。这就是为什么ANSI将C作为标准。
参考
#9
0
A good question never asked here is : what is the definition of "Language" ? Are the libraries part of a language ? Is "printf" part of the language ?
这里从来没有问过一个好问题:“语言”的定义是什么?图书馆是语言的一部分吗?“printf”是语言的一部分吗?
I think the answer, like almost always in human mind, can vary with the context.
我认为答案,就像人类的思维一样,会随环境而变化。
#1
66
C++ diverged from C in 1982-1983, and that's a long time in computer years. But, there are many C libraries with C++ compatibility, including the C standard library itself, and a steady stream of programs are ported across from C to C++. Many C programmers only know or use the features that are compatible with C++.
从1982年到1983年,c++偏离了C,这在计算机时代是很长的一段时间。但是,有许多具有c++兼容性的C库,包括C标准库本身,并且有稳定的程序流从C移植到c++。许多C程序员只知道或使用与c++兼容的特性。
They are defined by different ISO standards from separate committees. Even when they define compatible features, it is often defined in different terms.
它们由不同的ISO标准和不同的委员会定义。即使它们定义了兼容的特性,也常常用不同的术语来定义。
Referring to C/C++ is about as valid as referring to Italian/Spanish. You should be careful to whom and when you use such a term. But it's true that there is diffusion of ideas in both directions, and the similarities are more than coincidence.
C/ c++和意大利语/西班牙语一样有效。当你使用这个词时,你应该小心。但确实,思想在两个方向上都有传播,而且相似之处不仅仅是巧合。
#2
33
"C/C++" is precisely zero languages. It does not exist.
“C/ c++”正是零语言。它不存在。
On the other hand, C is a language.
另一方面,C是一种语言。
C++ is another language, which is kind of like C but also has classes and lots of other differences.
c++是另一种语言,它有点像C语言,但也有类和很多其他的区别。
To be clear, @Zoidberg was spot on:
需要澄清的是,@Zoidberg是:
C and C++ are two completely different languages. C with Classes was the predecessor of C++, but the term is still often used for non-modern C++ (e.g. that uses raw pointers all over the place).
C和c++是两种完全不同的语言。带类的C是c++的前身,但是这个术语仍然经常用于非现代的c++(例如,到处都使用原始指针)。
#3
23
It is two languages. Calling C++ "C with classes" is like calling an elephant a four legged animal. It seems true till you compare it to a mouse.
这是两种语言。把c++称为“带类的C”就像把大象叫做四条腿的动物。直到你把它比作鼠标,它才显得真实。
There are many languages which derive from C: C++, Java, C#, JavaScript, csh, the list goes on. They are all different in many ways but they share similar syntax.
有许多语言源自C: c++, Java, c#, JavaScript, csh,等等。它们在很多方面都不同,但是它们有相似的语法。
Of course C derived from B. But that is another story (and no one cares about B anymore.)
C当然是从B衍生而来的,但那是另一个故事(没有人再关心B了)。
#4
12
Simple answer: two languages
答案很简单:两种语言
They are two different languages, although almost any C code is valid (not necessarily good) C++ code.
它们是两种不同的语言,尽管几乎所有的C代码都是有效的(不一定是好的)c++代码。
C++ was at first thought about as "C, but with classes", but as the time passed, it differed more and more and now C code is very bad C++ code. You can learn C or C++ or both, but you usually don't mix them up (but you can).
c++最初被认为是“C,但是有类”,但是随着时间的推移,它变得越来越不同,现在C代码是非常糟糕的c++代码。你可以学习C或c++或两者,但你通常不会混淆它们(但你可以)。
#5
4
C/C++ is two languages. C is one language, and C++ is the other. C++ is considered a 'better' C. C is procedural, whereas C++ is object oriented. C++ has a lot of improvements over C, and has a similar syntax to C.
C / c++是两种语言。C是一种语言,c++是另一种语言。c++被认为是“更好的”C C是程序化的,而c++是面向对象的。与C相比,c++有很多改进,语法与C类似。
#6
4
They are two different languages. C++ is so named because part of it is rooted from C and compatible with C in some sense.
它们是两种不同的语言。c++之所以如此命名,是因为它的一部分源自C,在某种意义上与C兼容。
According to Scott Myers's Effective C++, we can view C++ as a unified language with the following 4 components:
根据Scott Myers有效的c++,我们可以将c++看作一种统一的语言,它包含以下4个部分:
- C language part, blocks, statements, preprocessor, etc
- C语言部分,块,语句,预处理器等
- Objected Oriented C++: including class, encapsulation, inheritance, polymorphism, etc
- 面向对象的c++:包括类、封装、继承、多态性等。
- Template C++: including C++ templates, metaprogramming stuff
- 模板c++:包括c++模板,元编程
- The STL.
- STL。
So C++ is more powerful than C in some sense.
所以c++在某种意义上比C更强大。
#7
1
The name "C" refers to a family of related languages, some of which are formalized as international standards. These include K&R C, ANSI C, C99, and C11.
“C”一词是指一系列相关语言,其中一些被正式定为国际标准。包括K&R C、ANSI C、C99和C11。
The name "C++" refers to a family of related languages, some of which are formalized as international standards. These include C++98, C++03, C++11, C++14, and the speculated C++17.
“c++”一词是指一系列相关语言,其中一些被正式定义为国际标准。其中包括c++ 98, c++ 03, c++ 11, c++ 14,以及推测的c++ 17。
The term "C/C++" is used by many people to informally refer to the intersection of C and C++, which has been intentionally maintained by the designers of C++.
“C/ c++”一词被许多人用来非正式地引用C和c++的交集,这是c++设计者故意维护的。
C++'s immediate predecessor was in fact originally called "C with Classes". This is detailed in Bjarne Stroustrup's 1994 book "The Design and Evolution of C++" (and also here). The name was eventually changed to "C++", largely as a courtesy to the C community because it had become too tempting for people to shorten "C with Classes" to just "C" or "new C".
c++的直接前身实际上最初被称为“类”。这在Bjarne Stroustrup 1994年的书《c++的设计与进化》(也在这里)中有详细的描述。这个名字最终被改成了“c++”,这主要是对C社区的一种礼遇,因为人们很容易将“C with Classes”缩写为“C”或“new C”。
There are many language features in C++ that are not in C (the reverse is true to a lesser extent). In particular, the class-based model, due to its capability to invoke implicit function calls, is so powerful that C++ has (rather organically) evolved higher-level programming styles that make the typical usage of C++ much different than that of C. The most notable examples of this are associated with the concept called Resource Acquisition Is Initialization, which is embodied in the standard classes string, vector, and shared_ptr as well as the stream classes of the standard I/O library.
c++中有许多语言特性不在C语言中(相反的情况在较小程度上是正确的)。特别是,基于类的模型,由于其能力来调用隐函数调用,是如此的强大,c++(而不是有机)的进化而来的高级编程风格,使c++完全不同的典型用法比C最引人注目的例子是相关的概念叫做资源获取初始化,这是体现在标准类字符串,向量,要查看以及流类标准I / O库。
Other notes:
另注:
-
GCC allows you to specify which of these language variations you want to compile against (as do other compilers, I'm sure), with some limitations.
GCC允许您指定要编译的这些语言变体中的哪一种(我确信其他编译器也是如此),但有一些限制。
-
C++98 and C++03 have minimal feature differences and are often treated as essentially the same language.
c++ 98和c++ 03具有最小的特性差异,通常被视为本质上相同的语言。
-
Top questions that address the common subset of C and C++:
解决C和c++的公共子集的最重要的问题:
- In C++ source, what is the effect of extern "C"?
- 在c++源代码中,outside的作用是什么?
- Where is C not a subset of C++?
- C不是c++的子集吗?
#8
1
IMHO, I think the answer is that C/C++ are not one language, but two which are:
我认为答案是C/ c++不是一种语言,而是两种语言:
- C Programming language
- C编程语言
- C++ Programming language
- c++编程语言
The C++ language is derived from the C language. C++ is the name for the C programming language with added 'classes' functionality. That means that the basic C language architecture has been enhanced to allow object oriented programming. It uses the "++" operator that means increment. C++ is an increment of C, which allows you to use procedural way or object oriented way or both of them in programming ways. C++ allows us to write code easier than C. But this does not mean that the C language is not suitable now, because we have C++. Each language is used for goal the purpose of software that is needed by a programmer. That's why ANSI made C a standard.
c++语言源自C语言。c++是添加了“类”功能的C编程语言的名称。这意味着基本的C语言体系结构得到了增强,允许面向对象编程。它使用“++”运算符表示增量。c++是C的一个增量,它允许您使用过程方式或面向对象方式,或者在编程方式中同时使用它们。c++允许我们编写比C更容易的代码,但这并不意味着C语言现在不合适,因为我们有c++。每一种语言都是为了实现程序员所需要的软件目的而使用的。这就是为什么ANSI将C作为标准。
参考
#9
0
A good question never asked here is : what is the definition of "Language" ? Are the libraries part of a language ? Is "printf" part of the language ?
这里从来没有问过一个好问题:“语言”的定义是什么?图书馆是语言的一部分吗?“printf”是语言的一部分吗?
I think the answer, like almost always in human mind, can vary with the context.
我认为答案,就像人类的思维一样,会随环境而变化。