PDA

View Full Version : The FAQ Board



medievalelks
04-18-2008, 06:59 AM
Found this on the FAQ board and it should probably be amended or removed, as it is misleading at best:

http://cboard.cprogramming.com/showthread.php?t=5352

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.

SlyMaelstrom
04-18-2008, 07:06 AM
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.

medievalelks
04-18-2008, 07:43 AM
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.

Mario F.
04-18-2008, 07:53 AM
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/Compatibility_of_C_and_C%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.

SlyMaelstrom
04-18-2008, 07:55 AM
No, that is simply not true.

http://david.tribble.com/text/cdiffs.htmI'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.

Prelude
04-18-2008, 07:57 AM
>I would like to see an example of standard C code that a C++ compiler won't compile


char *p = malloc ( 10 );

medievalelks
04-18-2008, 08:00 AM
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.

Mario F.
04-18-2008, 08:00 AM
char *p = malloc ( 10 );


pedantically speaking, yes. it won't compile.

Mario F.
04-18-2008, 08:01 AM
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

medievalelks
04-18-2008, 08:02 AM
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.

medievalelks
04-18-2008, 08:03 AM
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.

SlyMaelstrom
04-18-2008, 08:04 AM
>I would like to see an example of standard C code that a C++ compiler won't compile


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)

Mario F.
04-18-2008, 08:15 AM
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.

Prelude
04-18-2008, 08:24 AM
>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.

medievalelks
04-18-2008, 08:25 AM
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.

SlyMaelstrom
04-18-2008, 08:30 AM
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.*ahem*
The exception being, of course, the use of C++ keywords as identifiers in a C program.Let's make sure we read more clearly next time, thank you. :)

This is, of course, true and practically it is one of the best examples of why you can't take any old C program and throw it into a C++ compiler. Things like template, new, delete, etc were certainly used as identifiers in older C programs... however, it's not an example of why one language is not a superset of another, as any superset will have a larger vocabulary than it's subset.

... and that link doesn't contain "a lot of examples," of C99 code that will not compile in a C++ compiler and the examples that it does provide represent code that would never be used practically unless the code was intentionally obfuscated for various reasons.

Regardless, I will give you that the sentence shouldn't definite and should be changed... then again, I was agreeing that it should be changed since my very first post in this topic, I was simply explaining the reasoning behind the context.

medievalelks
04-18-2008, 08:33 AM
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 don't see any ambiguity in this statement:

"the point was that everything that can be compiled in C can be compiled in C++."

It is further clarified with this:

"It was designed that way".

Change "everything" to "much", and we can talk :-)

SlyMaelstrom
04-18-2008, 08:40 AM
I don't see any ambiguity in this statement:

"the point was that everything that can be compiled in C can be compiled in C++."

It is further clarified with this:

"It was designed that way".

Change "everything" to "much", and we can talk :-)...but it's basically just bickering at this point. I didn't imply to express anything more definite than the original statement (which had the clarity of using "good C program" rather than just "C program") and though I did... it was just a simple foul up of word usage. Anyway, I would appease you and change "everything" to "much", however it would kind of invalidate all of the posts that follow, so I won't, now.

I have no problem agreeing with you that it should be changed, however I don't find the statement that "All good C programs are also C++ programs" because the term "good" is relative to its context.

Mario F.
04-18-2008, 08:50 AM
Change "everything" to "much", and we can talk :-)

My vote is "most everything" :)

I agree with Sly. It's mostly nitpicking, won't you agree? But yes, it could be changed if anyone felt like doing it.

medievalelks
04-18-2008, 09:08 AM
...but it's basically just bickering at this point. I didn't imply to express anything more definite than the original statement (which had the clarity of using "good C program" rather than just "C program") and though I did... it was just a simple foul up of word usage. Anyway, I would appease you and change "everything" to "much", however it would kind of invalidate all of the posts that follow, so I won't, now.

I have no problem agreeing with you that it should be changed, however I don't find the statement that "All good C programs are also C++ programs" because the term "good" is relative to its context.

That is indeed unfortunate, especially on a board dedicated to C and C++ programming. I think I'll avoid the FAQs and just participate on the C++ board, and pray that newbies don't use the FAQs.

matsp
04-18-2008, 09:32 AM
The FAQ on this board is not currently maintained (at least not frequently), so bickering or not, it's unlikely to be fixed anytime soon [I do not know who would be responsible for such updates].

This is why the cpwiki.sourceforge.net was introduced, to be able to easily/quickly add/change FAQ entries.

--
Mats

Mario F.
04-18-2008, 09:38 AM
My understanding of the FAQ acronym has evolved throughout the times. Mostly, it is today a cross between Frequent Asked Questions and Important Questions and Their Answers. And this holds true for message board FAQs.

I always preferred more those FAQs that are not simply the result of a thread being moved, but instead the result of a conscious effort by some authoritative source. That said, I'm unsure if anyone would want to take the time and write such thing(s). Besides, you will most probably find way more references to http://www.parashift.com/c++-faq-lite/ on the C++ forum than any other link whatsoever throughout CBoard history - definitely you can count with the fingers of one hand links to the faq forum. (And Cline's exactly the type of FAQ I prefer.)

Frankly, in my humble opinion, if one post needs to be changed there, might as well gather a group of members and work on the whole FAQ forum. Throughout my apprenticeship of C++ that forum posed more questions to me than answers. Answers that I eventually found elsewhere; Cline's as mentioned before, and many other sources, including obviously the C++ forum.