Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C and C++ are interoperable languages? True or Not True?

Reply
Thread Tools

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

 
 
Chip
Guest
Posts: n/a
 
      01-08-2005
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

 
Reply With Quote
 
 
 
 
Ioannis Vranos
Guest
Posts: n/a
 
      01-08-2005
Chip wrote:

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




--
Ioannis Vranos

http://www23.brinkster.com/noicys
 
Reply With Quote
 
 
 
 
Sharad Kala
Guest
Posts: n/a
 
      01-08-2005

"Chip" <(E-Mail Removed)> wrote in message
> 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


 
Reply With Quote
 
Ivan Vecerina
Guest
Posts: n/a
 
      01-08-2005
"Chip" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form


 
Reply With Quote
 
Jon Wilson
Guest
Posts: n/a
 
      01-08-2005
> 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.
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      01-08-2005
Jon Wilson wrote:
>
>> 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.




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




--
Ioannis Vranos

http://www23.brinkster.com/noicys
 
Reply With Quote
 
E. Robert Tisdale
Guest
Posts: n/a
 
      01-08-2005
Chip wrote:

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[False,True] and [True,True] --> [True, True]????? bdb112 Python 45 04-29-2009 02:35 AM
fcalias zones in interoperable cisco MDS SAN directors pomikister Cisco 0 04-28-2008 01:49 PM
RE: Page.User.IsInRole True for AD group in VS.NET not true on samemachine once published wildman@noclient.net ASP .Net 0 03-10-2008 08:54 PM
SAS/C INTEROPERABLE WITH IBM C/C++ kk C Programming 4 01-21-2005 12:16 AM
How interoperable are XenPak devices with Cisco? Jeff Bush Cisco 0 07-24-2003 08:27 PM



Advertisments