Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old July 23rd, 2005, 12:30 AM
Chip
Guest
 
Posts: n/a
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

  #2  
Old July 23rd, 2005, 12:30 AM
Ioannis Vranos
Guest
 
Posts: n/a

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


Chip wrote:
[color=blue]
> 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[/color]

No.


[color=blue]
> 2. They are interoperable languages[/color]

No.

[color=blue]
> 3. C++ changes the syntax used in C[/color]

No.

[color=blue]
> 4. C++ evolved from C[/color]

Yes!


[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 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)[/color]


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



[color=blue]
> 2. Program written in C will work in a C++ environment (I agree)[/color]


No (not necessarily).

[color=blue]
> 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)[/color]



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




--
Ioannis Vranos

http://www23.brinkster.com/noicys
  #3  
Old July 23rd, 2005, 12:30 AM
Sharad Kala
Guest
 
Posts: n/a

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



"Chip" <chip_ling@yahoo.ca> wrote in message[color=blue]
> 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)[/color]

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++ ??
}
[color=blue]
> 2. Program written in C will work in a C++ environment (I agree)[/color]

Not true. Read above.

Sharad


  #4  
Old July 23rd, 2005, 12:31 AM
Ivan Vecerina
Guest
 
Posts: n/a

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


"Chip" <chip_ling@yahoo.ca> wrote in message
news:1105159313.098413.270560@f14g2000cwb.googlegr oups.com...[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]

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

[color=blue]
> 2. They are interoperable languages[/color]

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.

[color=blue]
> 3. C++ changes the syntax used in C[/color]

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

[color=blue]
> 4. C++ evolved from C[/color]

Yes, it was derived from 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 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.[/color]

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
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form


  #5  
Old July 23rd, 2005, 12:31 AM
Jon Wilson
Guest
 
Posts: n/a

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


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

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.
  #6  
Old July 23rd, 2005, 12:31 AM
Ioannis Vranos
Guest
 
Posts: n/a

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


Jon Wilson wrote:[color=blue]
>[color=green]
>> 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).[/color]
>
>
> 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.[/color]



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




--
Ioannis Vranos

http://www23.brinkster.com/noicys
  #7  
Old July 23rd, 2005, 12:31 AM
E. Robert Tisdale
Guest
 
Posts: n/a

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


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.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
get an element by id does not work! webEater answers 14 January 17th, 2007 10:25 PM
Singleton desing patter approach without function expressions... Luke Matuszewski answers 56 February 17th, 2006 08:25 PM
Is Python suitable for a huge, enterprise size app? john67 answers 53 July 19th, 2005 02:38 AM
Use of GPLed Python extension modules Tim Churches answers 36 July 18th, 2005 07:11 AM