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

Discussion in 'C++' started by Chip, Jan 8, 2005.

  1. Chip

    Chip Guest

    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
     
    Chip, Jan 8, 2005
    #1
    1. Advertising

  2. 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
     
    Ioannis Vranos, Jan 8, 2005
    #2
    1. Advertising

  3. Chip

    Sharad Kala Guest

    "Chip" <> 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
     
    Sharad Kala, Jan 8, 2005
    #3
  4. "Chip" <> wrote in message
    news:...
    > 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
     
    Ivan Vecerina, Jan 8, 2005
    #4
  5. Chip

    Jon Wilson Guest

    > 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.
     
    Jon Wilson, Jan 8, 2005
    #5
  6. 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
     
    Ioannis Vranos, Jan 8, 2005
    #6
  7. 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.
     
    E. Robert Tisdale, Jan 8, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. André
    Replies:
    3
    Views:
    1,617
  2. kk

    SAS/C INTEROPERABLE WITH IBM C/C++

    kk, Jan 20, 2005, in forum: C Programming
    Replies:
    4
    Views:
    516
    xarax
    Jan 21, 2005
  3. Replies:
    0
    Views:
    846
  4. bdb112
    Replies:
    45
    Views:
    1,370
    jazbees
    Apr 29, 2009
  5. Peter Alvin
    Replies:
    4
    Views:
    106
    Brian Candler
    Sep 29, 2008
Loading...

Share This Page