The FAQ Board

This is a discussion on The FAQ Board within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Found this on the FAQ board and it should probably be amended or removed, as it is misleading at best: ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    890

    The FAQ Board

    Found this on the FAQ board and it should probably be amended or removed, as it is misleading at best:

    FAQ Difference between C, C++ and C#

    C++ - a "better C" (Stroustrop, guy who made it). It is an extension of C. All good C programs are also C++ programs, but the reverse is not true. Contains elements that generally make large scale programming easier.

    C and C++ may be related, but they are different languages with different standards and different design goals. And there are myriad "good C programs" that are not C++ programs.

    A fun experiment would be to download any moderately sized C project from SourceForge and try to compile it with a C++ compiler.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Quote Originally Posted by medievalelks View Post
    C and C++ may be related, but they are different languages with different standards and different design goals. And there are myriad "good C programs" that are not C++ programs.
    While I agree that the wording should be changed, the point was that everything that can be compiled in C can be compiled in C++. It was designed that way (even references to C libraries)... however, I am reading it and getting the feeling as though it's saying "Don't use C! C++ is like C, only better!"

    Should be changed.
    Sent from my iPad®

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by SlyMaelstrom View Post
    While I agree that the wording should be changed, the point was that everything that can be compiled in C can be compiled in C++.
    No, that is simply not true.

    http://david.tribble.com/text/cdiffs.htm

    When we say that C is incompatible with C++ with respect to a specific language feature, we mean that a C program that employs that feature either is not valid C++ code and thus will not compile as a C++ program, or that it will compile as a C++ program but will exhibit different behavior than the same program compiled as a C program. In other words, an incompatible C feature is valid as C code but not as C++ code.
    Last edited by medievalelks; 04-18-2008 at 08:52 AM.

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,532
    Quote Originally Posted by medievalelks View Post
    No, that is completely untrue.
    No. It's not. It may be untrue for some cases. It's not completely untrue.

    For a lighter reading: http://en.wikipedia.org/wiki/Compati...nd_C&#37;2B%2B
    For a more detailed description: http://david.tribble.com/text/cdiffs.htm

    Also GNU caters many of these differences in the form of C++ compiler extensions.

    On those cases remaining where it may still not be possible to compile C code as C++ it is often due to the lack of will on behalf of the programmer to change his C code. There may be some cases where it is still not possible.

    But in general terms code for C compiles as C++. And that was the meaning. It is correct. Not completely untrue as you say.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Quote Originally Posted by medievalelks View Post
    No, that is simply not true.

    http://david.tribble.com/text/cdiffs.htm
    I'm not sure of any specific examples of C code that will not compile with a C++ compiler. I know of several situations where certain C code might exibit undefined behavior in a C++ compiler (specifically regarding dynamic memory allocation and such)... however, I would like to see an example of standard C99 code that a C++ compiler won't compile (whcih is the only thing I suggested in my post). The exception being, of course, the use of C++ keywords as identifiers in a C program.
    Last edited by SlyMaelstrom; 04-18-2008 at 09:01 AM.
    Sent from my iPad®

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I would like to see an example of standard C code that a C++ compiler won't compile
    Code:
    char *p = malloc ( 10 );
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by Mario F. View Post
    No. It's not. It may be untrue for some cases. It's not completely untrue
    The statement that everything that is valid C is also valid C++ - is completely untrue. It is a false statement, with no shades of grey.

  8. #8
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,532
    Quote Originally Posted by Prelude View Post
    Code:
    char *p = malloc ( 10 );
    pedantically speaking, yes. it won't compile.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #9
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,532
    Quote Originally Posted by medievalelks View Post
    The statement that everything that is valid C is also valid C++ - is completely untrue. It is a false statement, with no shades of grey.
    extern c
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by Mario F. View Post
    pedantically speaking, yes. it won't compile.

    There's nothing pedantic about it. It either compiles or does not.

    Sorry, but it's time to kill the myth that C++ is a superset of C.

  11. #11
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by Mario F. View Post
    extern c

    You've already been given one counter-example, and there are plenty more. Therefore, it's false (i.e. completely untrue) to say that everything that is valid C is also valid C++.

    I'm not sure why this is so difficult.

  12. #12
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Quote Originally Posted by Prelude View Post
    >I would like to see an example of standard C code that a C++ compiler won't compile
    Code:
    char *p = malloc ( 10 );
    Yes, that's true... for some reason I was thinking implicit casts would only generate a warning and not an error (It's been too long since I've used C code). I couldn't say there are PLENTY more exampels of this... but there is certainly this and perhaps a few more. This is, as far as I know, the only example of C code that will not compile in C++ and can be found in a practical C application (that is to say, people aren't doing strange things just to make the compiler give an error)
    Last edited by SlyMaelstrom; 04-18-2008 at 09:07 AM.
    Sent from my iPad®

  13. #13
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,532
    Quote Originally Posted by medievalelks View Post
    You've already been given one counter-example, and there are plenty more. Therefore, it's false (i.e. completely untrue) to say that everything that is valid C is also valid C++.
    Look medievaleks, we may agree to disagree. That's is also a good starting point.

    The problem is how you and I are reading "everything" in the context of the full post. I know, as you do, not all C code compiles in C++. I read everything as "in general terms". You prefer to adopt "everything" at face value.

    As I said before in general terms C code can be compiled as C++. With a little bit of effort you can use compiler extensions, extern c and changes to the code to produce satisfying results. There may be some code that simply can't be compiled, period. But generally it can if you want.

    Contraty to you, I don't think " it's time to kill the myth that C++ is a superset of C". First because i'm unsure there is such a myth, second because it won't be us here that will suddenly change the world.

    I however also agree with you. And that is because for anyone not in the know (and that is only anyone just now learning C or C++. Say... 6 months of practice?) "everything" can be seen as... everything.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  14. #14
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I couldn't say there are PLENTY more exampels of this...
    You didn't ask for "PLENTY" though, you asked for one. I could give you well more than plenty for the current state of the standards though. C++ hasn't caught up to C99 yet, and C99 is being used in practical applications.

    Here's the reality:

    C and C++ are not 100% syntactically or semantically compatible. As such, you can't take any C program and compile it as C++. However, often you need little more than minor changes to compile C as C++, especially if the C code was written with C++ compatibility in mind.
    My best code is written with the delete key.

  15. #15
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by SlyMaelstrom View Post
    Yes, that's true... for some reason I was thinking implicit casts would only generate a warning and not an error (It's been too long since I've used C code). I couldn't say there are PLENTY more exampels of this... but there is certainly this and perhaps a few more. This is, as far as I know, the only example of C code that will not compile in C++ and can be found in a practical C application (that is to say, people aren't doing strange things just to make the compiler give an error)
    Anything that names an identifier using a keyword introduced by C++ (e.g. new, delete) would fail to compile. The article I linked points out a lot more. Keep in mind that there was C code written decades before C++ was created.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Constructor problem
    By rebel in forum C++ Programming
    Replies: 22
    Last Post: 01-11-2006, 06:45 AM
  2. FAQ Board
    By Noobie in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-16-2003, 09:18 AM
  3. Isn't the C Board a cool name?
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 12-23-2002, 01:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21