[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

Differences between C and C++

Asbjørn Sæbø

2/9/2011 7:59:00 PM


This may be a FAQ, but I did some searching and did not find an answer
that satisfied me.

I seem to remember people on this group claiming strongly that despite
their similarities, C and C++ are two different languages, and are
best treated as such. Can anyone point me to a summary of the
differences between these two languages, and also to information about
the possible consequences of e.g. compiling one language in a compiler
intended for the other? (Obviously, much of C++ will not compile at
all in a C compiler. That is not the interesting part.)

With kind regards
Asbjørn Sæbø



--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
44 Answers

Chris H

2/10/2011 7:32:00 PM

0

In message <86y65pc73s.fsf@undring.hildring>, Asbjørn Sæbø
<asbjs@stud.ntnu.no> writes
>
>This may be a FAQ, but I did some searching and did not find an answer
>that satisfied me.
>
>I seem to remember people on this group claiming strongly that despite
>their similarities, C and C++ are two different languages, and are
>best treated as such. Can anyone point me to a summary of the
>differences between these two languages, and also to information about
>the possible consequences of e.g. compiling one language in a compiler
>intended for the other? (Obviously, much of C++ will not compile at
>all in a C compiler. That is not the interesting part.)

Looking at the chart on the wall C was incrementally developed from
BCPL that came from CPL.

in the 1970's we had K&R C, the first definition.
ANSI/ISO C was standardised in 1989/90 and then ISO C in 95 and 99

C++ was developed from "C with Classes" (1980) which was developed
from 1975 K&R C AND Simula 68

C++ came about in 1985 ish with influences from Algo 68 and additional
input from Simula 68

So there is a LOT of Simula in C++ as well as Algo

Moving on... in 1990 we had C++ ARM,( Annotated Reference Manual not
ARM MCU's ) developed from C++ but also with influences from Ada, ANSI
C, ML and CLu

C++ was further developed into the mid 90's when it became an ISO
standard.

So whilst sharing syntax that appears similar C and C++ diverged in
197* and whilst C carried on in one direction C++ was a hybrid of C and
Simula which was developed independently from C with influenced from 5
other languages.

The confusion generally arises because in the early days (from memory)
a front end call C-Front was used to translate C++ into C for
compilation until C++ compilers were built from scratch.

Thus the myth started that C++ was a super set of C.



--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



Tim Rentsch

2/10/2011 7:59:00 PM

0

Chris H <chris@phaedsys.org> writes:

> In message <86y65pc73s.fsf@undring.hildring>, Asbj@{o/}rn S@C3{A6}b@{o/}
> <asbjs@stud.ntnu.no> writes
>>
>>This may be a FAQ, but I did some searching and did not find an answer
>>that satisfied me.
>>
>>I seem to remember people on this group claiming strongly that despite
>>their similarities, C and C++ are two different languages, and are
>>best treated as such. Can anyone point me to a summary of the
>>differences between these two languages, and also to information about
>>the possible consequences of e.g. compiling one language in a compiler
>>intended for the other? (Obviously, much of C++ will not compile at
>>all in a C compiler. That is not the interesting part.)
>
> Looking at the chart on the wall C was incrementally developed from
> BCPL that came from CPL.
>
> in the 1970's we had K&R C, the first definition.
> ANSI/ISO C was standardised in 1989/90 and then ISO C in 95 and 99
>
> C++ was developed from "C with Classes" (1980) which was developed
> from 1975 K&R C AND Simula 68 [snip further]

I expect you mean Simula 67 -

http://en.wikipedia.org/w...

James Kuyper

2/11/2011 1:51:00 AM

0

On 02/10/2011 02:31 PM, Chris H wrote:
> In message<86y65pc73s.fsf@undring.hildring>, Asbj�rn S�b�
> <asbjs@stud.ntnu.no> writes
>>
>> This may be a FAQ, but I did some searching and did not find an answer
>> that satisfied me.
>>
>> I seem to remember people on this group claiming strongly that despite
>> their similarities, C and C++ are two different languages, and are
>> best treated as such. Can anyone point me to a summary of the
>> differences between these two languages, and also to information about
>> the possible consequences of e.g. compiling one language in a compiler
>> intended for the other? (Obviously, much of C++ will not compile at
>> all in a C compiler. That is not the interesting part.)
>
> Looking at the chart on the wall C was incrementally developed from
> BCPL that came from CPL.
>
> in the 1970's we had K&R C, the first definition.
> ANSI/ISO C was standardised in 1989/90 and then ISO C in 95 and 99
>
> C++ was developed from "C with Classes" (1980) which was developed
> from 1975 K&R C AND Simula 68

And C with Classes was originally intended to be no more than an
extension to C, a concept that never ceased to influence the development
of C++, even long after it had diverged enough that it was clearly a
different language.

> C++ came about in 1985 ish with influences from Algo 68 and additional
> input from Simula 68

And it was developed with an explicit design philosophy, which
influenced a great many of the design decisions, to maintain a fair
amount of backwards compatibility with C. In fact, there's been a lot of
criticism of precisely those design decisions which were made to retain
a level of backwards compatibility.

> So there is a LOT of Simula in C++ as well as Algo
>
> Moving on... in 1990 we had C++ ARM,( Annotated Reference Manual not
> ARM MCU's ) developed from C++ but also with influences from Ada, ANSI
> C, ML and CLu
>
> C++ was further developed into the mid 90's when it became an ISO
> standard.

And the C and C++ committees interacted strongly, with the goal of
avoiding gratuitous incompatibilities between C and C++.

> So whilst sharing syntax that appears similar C and C++ diverged in
> 197* and whilst C carried on in one direction C++ was a hybrid of C and
> Simula which was developed independently from C with influenced from 5
> other languages.

To summarize my comments on your history: C++ didn't just diverge wildly
from C randomly; it was deliberately kept fairly close to C, far closer
than it would have been had there not been a deliberate decision to
retain a fair amount of C compatibility. C is NOT just a language that
inspire the design of C++, the connections between the two languages are
much tighter than that.

> The confusion generally arises because in the early days (from memory)
> a front end call C-Front was used to translate C++ into C for
> compilation until C++ compilers were built from scratch.
>
> Thus the myth started that C++ was a super set of C.

I doubt that awareness of that historical background has as much to do
with that "myth" as other, more important things, such as the following
list of similarities, which I'll organize by sections of the C standard:

6.4.1: Virtually every C90 keyword is also a C++ keyword, and when used
in typical C code, most of them have essentially the same meaning as in
C++. Also, many of the new C90 keywords are also keywords in C++03.

6.4.2: The rules for legal identifiers in C are almost identical to
those of C++.

6.4.3: UCNs work essentially the same in both languages.

6.4.4: Most C90 constants are C++ literals, almost always with the same
meaning (the biggest difference being the type of 'a').

6.4.5: string literals are pretty much the same in both languages,
except that they are const-qualified in C++, but they're not safely
writable in either language, so that won't have much effect on
well-written C code.

6.4.6: Every C punctuator is also a C++ punctuator.

6.4.7: Both languages have essentially the same rules for header names.

6.4.8: Both languages have essentially the same rules for preprocessing
numbers.

6.4.9: Every C90 comment is also a C++ comment; and C99 comments are
essentially the same as C++ comments.

6.5: Every C90 expression is also a C++ expression, and when used in
typical C code, almost always has the same meaning in C++.

6.6: All C constant expressions are also C++ constant expressions.

6.7: Most C declarations carry essentially the same meaning in C++,
though there are some changes the scope and name space rules.

6.8: Every C statement type is also a C++ statement type. While some of
the details are different in C++, in typical C code, they work the same
way in both languages.

6.10: Preprocessing directives: every C90 preprocessing directive is
also a C++ preprocessing directive, with essentially the same meaning.

7: The entire C standard library was incorporated with only a few
modifications into the C++ standard library. While things like <cstdio>
and std::printf do exist, you don't have to use them: <stdio.h> and
printf() will work almost exactly as they do in C.

I put this list together in a hurry - some of my "almost" and
"essentially" qualifiers may have been unnecessary, and I may have
failed to use them on some statements where they were needed - but I'm
sure that I didn't make enough errors in the above summary to change my
final conclusion:

The concept that C is a strict subset of C++ is indeed a myth, but
mainly because of the word "strict". The concept that C doesn't even
come close to being a subset of C++ is a myth that strays much farther
from the truth.

--
James Kuyper

Michael Press

2/11/2011 5:40:00 AM

0

In article <ij24me$a4b$1@news.eternal-september.org>,
James Kuyper <jameskuyper@verizon.net> wrote:


[...]

> 6.4.1: Virtually
[...]
> most of them have essentially
[...]
> many
> 6.4.2:
[...]
> almost identical to
> 6.4.3:
[...]
> work essentially the same.
[...]
> 6.4.4: Most
[...]
> almost always
[...]
> 6.4.5:
> pretty much the same
[...]
> except
[...]
> won't have much effect
[...]
> 6.4.6: Every C punctuator is also a C++ punctuator.
>
> 6.4.7:
[...]
> essentially the same
[...]
> 6.4.8:
[...]
> essentially the same
[...]
> 6.4.9:
[...]
> essentially the same
[...]
> 6.5:
[...]
> almost always
[...]
> 6.6: All C constant expressions are also C++ constant expressions.
>
> 6.7: Most
[...]
> essentially the same
[...]
> though
[...]
> 6.8: Every C statement type is also a C++ statement type. While some of
> the details are different in C++, in typical C code, they work the same
> way in both languages.
>
> 6.10:
[...]
> essentially the same meaning.
>
> 7:
[...]
> only a few
> modifications
[...]
> almost exactly
[...]
>
> I put this list together in a hurry - some of my "almost" and
> "essentially" qualifiers may have been unnecessary, and I may have
> failed to use them on some statements where they were needed - but I'm
> sure that I didn't make enough errors in the above summary to change my
> final conclusion:
>
> The concept that C is a strict subset of C++ is indeed a myth, but
> mainly because of the word "strict". The concept that C doesn't even
> come close to being a subset of C++ is a myth that strays much farther
> from the truth.

--
Michael Press

Chris H

2/11/2011 9:40:00 AM

0

In message <ij24me$a4b$1@news.eternal-september.org>, James Kuyper
<jameskuyper@verizon.net> writes

>To summarize my comments on your history: C++ didn't just diverge
>wildly from C randomly; it was deliberately kept fairly close to C, far
>closer than it would have been had there not been a deliberate decision
>to retain a fair amount of C compatibility. C is NOT just a language
>that inspire the design of C++, the connections between the two
>languages are much tighter than that.

>
>6.4.1: Virtually every C90 keyword is also a C++ keyword

Ie Most

>6.4.2: The rules for legal identifiers in C are almost identical to
>those of C++.

Almost identical == different

>6.4.3: UCNs work essentially the same in both languages.

Essentially they same but not the same

>6.4.4: Most C90 constants are C++ literals, almost always with the same
>meaning (the biggest difference being the type of 'a').

*Almost* always the same


>6.4.5: string literals are pretty much the same in both languages,
>except that they are const-qualified in C++, but they're not safely
>writable in either language, so that won't have much effect on well-
>written C code.

Pretty much the same *except*


>6.4.7: Both languages have essentially the same rules for header names.
>
>6.4.8: Both languages have essentially the same rules for preprocessing
>numbers.

"Essentially the same" not actually the same

>6.5: Every C90 expression is also a C++ expression, and when used in
>typical C code, almost always has the same meaning in C++.

"Almost" always

>6.7: Most C declarations carry essentially the same meaning in C++,
>though there are some changes the scope and name space rules.

"Most" again


>6.8: Every C statement type is also a C++ statement type. While some of
>the details are different in C++, in typical C code, they work the same
>way in both languages.


"Whist some details are different"


>7: The entire C standard library was incorporated with only a few
>modifications into the C++ standard library. While things like <cstdio>
>and std::printf do exist, you don't have to use them: <stdio.h> and
>printf() will work almost exactly as they do in C.

"Almost exactly" but not identically

>I put this list together in a hurry - some of my "almost" and
>"essentially" qualifiers may have been unnecessary, and I may have
>failed to use them on some statements where they were needed - but I'm
>sure that I didn't make enough errors in the above summary to change my
>final conclusion:


Agreed. But my point is that they are SIMILAR but different and these
small differences scattered around very similar syntax is dangerous
when people treat C and C++ as a subset/superset and this is where
errors occur particularly using C source in a C++ compiler and Vice
versa

>The concept that C is a strict subset of C++ is indeed a myth, but
>mainly because of the word "strict".

We agree.

> The concept that C doesn't even come close to being a subset of C++ is
>a myth that strays much farther from the truth.

I would disagree but them most of my work in in safety critical and high
reliability SW

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



Chris H

2/11/2011 9:41:00 AM

0


That is a long list of "if" , "maybe" , "almost", "similar" and "pretty
much"

Or in other words "Different"



In message <rubrum-DC4157.21393810022011@Hello.NetWork>, Michael Press
<rubrum@pacbell.net> writes
>In article <ij24me$a4b$1@news.eternal-september.org>,
> James Kuyper <jameskuyper@verizon.net> wrote:
>
>
>[...]
>
>> 6.4.1: Virtually
>[...]
>> most of them have essentially
>[...]
>> many
>> 6.4.2:
>[...]
>> almost identical to
>> 6.4.3:
>[...]
>> work essentially the same.
>[...]
>> 6.4.4: Most
>[...]
>> almost always
>[...]
>> 6.4.5:
>> pretty much the same
>[...]
>> except
>[...]
>> won't have much effect
>[...]
>> 6.4.6: Every C punctuator is also a C++ punctuator.
>>
>> 6.4.7:
>[...]
>> essentially the same
>[...]
>> 6.4.8:
>[...]
>> essentially the same
>[...]
>> 6.4.9:
>[...]
>> essentially the same
>[...]
>> 6.5:
>[...]
>> almost always
>[...]
>> 6.6: All C constant expressions are also C++ constant expressions.
>>
>> 6.7: Most
>[...]
>> essentially the same
>[...]
>> though
>[...]
>> 6.8: Every C statement type is also a C++ statement type. While some of
>> the details are different in C++, in typical C code, they work the same
>> way in both languages.
>>
>> 6.10:
>[...]
>> essentially the same meaning.
>>
>> 7:
>[...]
>> only a few
>> modifications
>[...]
>> almost exactly
>[...]
>>
>> I put this list together in a hurry - some of my "almost" and
>> "essentially" qualifiers may have been unnecessary, and I may have
>> failed to use them on some statements where they were needed - but I'm
>> sure that I didn't make enough errors in the above summary to change my
>> final conclusion:
>>
>> The concept that C is a strict subset of C++ is indeed a myth, but
>> mainly because of the word "strict". The concept that C doesn't even
>> come close to being a subset of C++ is a myth that strays much farther
>> from the truth.
>

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



James Kuyper

2/11/2011 12:08:00 PM

0

On 02/11/2011 04:39 AM, Chris H wrote:
....
> Ie Most
....
> Almost identical == different

Yes, and different != distinct

> Essentially they same but not the same
....
> *Almost* always the same
....
> Pretty much the same *except*
....
> "Essentially the same" not actually the same
....
> "Almost" always
....
> "Most" again
....
> "Whist some details are different"
....
> "Almost exactly" but not identically

Thank you for noticing; I tried to be careful to include all of the
qualifiers needed to make my statements accurate. I'm glad to see that
you don't disagree with any of them, neither by implying that the
differences are significantly larger (or smaller) than implied by those
qualifiers.

>> I put this list together in a hurry - some of my "almost" and
>> "essentially" qualifiers may have been unnecessary, and I may have
>> failed to use them on some statements where they were needed - but I'm
>> sure that I didn't make enough errors in the above summary to change my
>> final conclusion:
>
>
> Agreed. But my point is that they are SIMILAR but different and these

I was talking about the similarities, without in any way, shape, or form
implying that there were no differences. Why would you think otherwise,
after having so carefully noted all of the qualifiers that I inserted
specifically to express that concept?

....
>> The concept that C is a strict subset of C++ is indeed a myth, but
>> mainly because of the word "strict".
>
> We agree.
>
>> The concept that C doesn't even come close to being a subset of C++ is
>> a myth that strays much farther from the truth.
>
> I would disagree but them most of my work in in safety critical and high
> reliability SW

The differences between two arbitrarily chosen languages could be so
numerous as to preclude, for all practical purposes, reliable conversion
of safe software from one language to the other; yet that would not
exclude the possibility that the differences are few in comparison with
the similarities. I would deny emphatically that C and C++ even come
close to being that different.

--
James Kuyper

Chris H

2/11/2011 12:30:00 PM

0

In message <ij38r9$7h5$1@news.eternal-september.org>, James Kuyper
<jameskuyper@verizon.net> writes
>On 02/11/2011 04:39 AM, Chris H wrote:
>...
>> Ie Most
>...
>> Almost identical == different
>
>Yes, and different != distinct
>
>> Essentially they same but not the same
>...
>> *Almost* always the same
>...
>> Pretty much the same *except*
>...
>> "Essentially the same" not actually the same
>...
>> "Almost" always
>...
>> "Most" again
>...
>> "Whist some details are different"
>...
>> "Almost exactly" but not identically
>
>Thank you for noticing; I tried to be careful to include all of the
>qualifiers needed to make my statements accurate. I'm glad to see that
>you don't disagree with any of them, neither by implying that the
>differences are significantly larger (or smaller) than implied by those
>qualifiers.
>
>>> I put this list together in a hurry - some of my "almost" and
>>> "essentially" qualifiers may have been unnecessary, and I may have
>>> failed to use them on some statements where they were needed - but I'm
>>> sure that I didn't make enough errors in the above summary to change my
>>> final conclusion:
>>
>>
>> Agreed. But my point is that they are SIMILAR but different and these
>
>I was talking about the similarities, without in any way, shape, or
>form implying that there were no differences. Why would you think
>otherwise, after having so carefully noted all of the qualifiers that I
>inserted specifically to express that concept?
>
>...
>>> The concept that C is a strict subset of C++ is indeed a myth, but
>>> mainly because of the word "strict".
>>
>> We agree.
>>
>>> The concept that C doesn't even come close to being a subset of C++ is
>>> a myth that strays much farther from the truth.
>>
>> I would disagree but them most of my work in in safety critical and high
>> reliability SW
>
>The differences between two arbitrarily chosen languages could be so
>numerous as to preclude, for all practical purposes, reliable
>conversion of safe software from one language to the other; yet that
>would not exclude the possibility that the differences are few in
>comparison with the similarities. I would deny emphatically that C and
>C++ even come close to being that different.


I am being a devils advocate. If you approach the subject thinking these
are two different but similar languages you should have few problems. I
was only trying to stop those people who thing C is a subset of C++ and
assume because they look similar they are interchangeable

BJ has written that there is no such language as C/C++ and that whilst
very similar there are many difference to trap the unwary.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



Seebs

2/12/2011 5:52:00 PM

0

On 2011-02-11, Chris H <chris@phaedsys.org> wrote:
> That is a long list of "if" , "maybe" , "almost", "similar" and "pretty
> much"

> Or in other words "Different"

UK English and US English are pretty comparable. There are cases where
they differ. Heck, there are sentences which have their meaning completely
reversed between the two languages. But most people tend to view them as
so similar that some call them "dialects" of the same "language".

I'd tend to view the "common subset" parts of C and C++ as being about like
US and UK English. It would be foolhardy to ignore the differences, but that
doesn't mean they're a huge deal for most writers.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seeb... <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/...(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

Tetsuya

2/13/2011 10:39:00 AM

0

On 02/09/2011 08:59 PM, Asbjørn Sæbø wrote:
>
> This may be a FAQ

may?
MAY?
*MAY* ?
No, are you serious? You _can't_ be serious, come on...

--
God is real, unless if declared integer.
Powered by Debian GNU/Linux squeeze
Linux 2.6.32-3-686 #1 SMP Thu Feb 25 06:14:20 UTC 2010
Uptime: 6 days, 13:45, 2 users, load average: 0.16, 0.19, 0.28