Chip wrote:
[color=blue]
> I've just gone thru a so called e-learning course on the web
> and I found that one of the test question is interesting.
>
> Here is the question:
>
> What is the relationship between the C and C++ programming languages?
>
> 1. They are both object-oriented programming languages[/color]
No. C is *not* an object oriented programming language
because it does not support inheitance.
You can force C compilers to "adopt" derived types
through a pointer using an explicit cast
and you can mimick run-time polymorphism by including
a pointer to a virtual function table in the base type
but this is tedious, unreliable and may not be prortable everywhere.
[color=blue]
> 2. They are interoperable languages[/color]
No. Interoperability is determined by the implementations
and *not* by the standard language definitions.
There isn't even a guarantee that
code emitted from two different implementations of the same language
are interoperable.
But, in fact, a high degree of interoperability
among different implementations exists
event for different computer programming languages
partly because they all conform
to the same Application Binary Interface (ABI) --
usually the C ABI -- for any given platform
(machine architecture and operating system combination).
[color=blue]
> 3. C++ changes the syntax used in C[/color]
No.
[color=blue]
> 4. C++ evolved from C[/color]
No. C++ *extends* C.
[color=blue]
> I select the choice number 4 as my answer.
> (You are allowed to select more than one choice
> if you think they are correct.)[/color]
[color=blue]
> But when I look at the model answer,
> it says that both choice 2 and 4 are correct.
> Well, I'm pretty sure choice number 4 is correct
> but I don't think choice number 2 is [correct].[/color]
Code emitted by C and C++ compilers may be interoperable
but this has almost nothing to do with the language
except that the C++ extern "C" feature *helps* with linkage.
But, even if, you can link C an C++ code together,
there is no guarantee that they use compatible
argument passing and value return conventions.
[color=blue]
> So I called up the Online Mentor and chat with him for half an hour
> but the expert on the other side cannot give me a satisfy answer.
>
> Here is the explanation given by the mentor.
> 1. C is a subset of C++. (I agree).[/color]
Mostly correct.
[color=blue]
> 2. Program written in C will work in a C++ environment. (I agree.)[/color]
Usually, but there are important exceptions.
[color=blue]
> 3. Program written in C++ without using any C++ [extensions] will work in a
> C environment. (I agree, but I would rather call it a C program instead.)
> 4. So they are interoperable. (I don't get it)
> Anybody can enlighten me please.[/color]
The term "interoperable" implies more than compatible linkage.
If your C and C++ code are interoperable,
it is because your C and C++ compilers also conform to the same ABI.
I used Google
http://www.google.com/
to search for
+"C ABI" +"interoperability"
and I found lots of stuff.