C and C++ are interoperable languages? True or Not True?

C

Chip

Hi all,

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
2. They are interoperable languages
3. C++ changes the syntax used in C
4. C++ evolved from C

I select the choice number 4 as my answer. (You are allowed to select
more than one choice if you think they are corrected)

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'm
don't think choice number 2 is. 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)
2. Program written in C will work in a C++ environment (I agree)
3. Program written in C++ without using any C++ feature 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.

Rgds,
Chip Ling
 
I

Ioannis Vranos

Chip said:
Hi all,

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
No.



2. They are interoperable languages
No.


3. C++ changes the syntax used in C
No.


4. C++ evolved from C
Yes!




I select the choice number 4 as my answer. (You are allowed to select
more than one choice if you think they are corrected)

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'm
don't think choice number 2 is. 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)


No. C90 with few differences was a subset of C++. However the most
recent standard of C is C99 and there are many differences.



2. Program written in C will work in a C++ environment (I agree)


No (not necessarily).

3. Program written in C++ without using any C++ feature will work in a
C environment (I agree, but I would rather call it a c program instead)



More accurately, a C++ program which is written by using the C subset
C90) of C++, is also a valid C program (it compiles).


However under a C99 compiler the source code may have different meanings
(for example the largest unsigned integral built in type in C++ is
unsigned long, while in C99 is unsigned long long).
 
S

Sharad Kala

Chip said:
Hi all,

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
2. They are interoperable languages
3. C++ changes the syntax used in C
4. C++ evolved from C

I select the choice number 4 as my answer. (You are allowed to select
more than one choice if you think they are corrected)

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'm
don't think choice number 2 is. 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)

Not exactly. That would mean every C program is a C++ program which isn't
the case actually.

int main(void)
{
int class; // Valid C++ ??
}
2. Program written in C will work in a C++ environment (I agree)

Not true. Read above.

Sharad
 
I

Ivan Vecerina

Chip said:
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

Only C++ has built-in support for the object-oriented programming
paradigm. You can do OOP in C, but it is cumbersome.

2. They are interoperable languages

They have a large common subset, which makes them largely interoperable
in practice. There is a number of incompatibilities, but committees who
define both languages collaborate closely to ensure good
interoperability.
Based on this, I'd be very tempted to say yes.

3. C++ changes the syntax used in C

It extends it, but doesn't really change it.

4. C++ evolved from C

Yes, it was derived from C.

I select the choice number 4 as my answer. (You are allowed to select
more than one choice if you think they are corrected)

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'm
don't think choice number 2 is. 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)
2. Program written in C will work in a C++ environment (I agree)
3. Program written in C++ without using any C++ feature 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.

Can you name 2 languages that are more interoperable than C and C++ ?


I do not think the question is great an unequivocal.
But I wouldn't say that the 'correct' answer is wrong.


Regards,
Ivan
 
J

Jon Wilson

However under a C99 compiler the source code may have different meanings
(for example the largest unsigned integral built in type in C++ is
unsigned long, while in C99 is unsigned long long).

slightly OT, but slightly amusing as well
Have you ever tried to compile the following with gcc?

int main()
{
long l1;
long long l2;
long long long l3;

return 0;
}

The first two declarations work fine, but the third one gives the error
message:

longlonglong.c: In function `main':
longlonglong.c:5: error: `long long long' is too long for GCC

I was amused.
 
I

Ioannis Vranos

Jon said:
slightly OT, but slightly amusing as well
Have you ever tried to compile the following with gcc?

int main()
{
long l1;
long long l2;
long long long l3;

return 0;
}

The first two declarations work fine, but the third one gives the error
message:

longlonglong.c: In function `main':
longlonglong.c:5: error: `long long long' is too long for GCC

I was amused.



Yes you are right, this one is really good! :))
 
E

E. Robert Tisdale

Chip said:
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

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.
2. They are interoperable languages

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).
3. C++ changes the syntax used in C
No.

4. C++ evolved from C

No. C++ *extends* C.
I select the choice number 4 as my answer.
(You are allowed to select more than one choice
if you think they are correct.)
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].

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.
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).

Mostly correct.
2. Program written in C will work in a C++ environment. (I agree.)

Usually, but there are important exceptions.
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top