Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > diff C C++

Reply
Thread Tools

diff C C++

 
 
Rob Hoelz
Guest
Posts: n/a
 
      12-20-2006
I've been compiling a list of the differences between C and C++, and
I'd like to see how thorough I've been. Could any of you go over this
list and see if I've missed anything?

Here's the list:

Mid-scope declarations
Default function parameters
new/delete operators
Better implementation of const
References
Exception handling
"Catch all" catch block
Classes
Constructors/Destructors
Access modifiers
Inheritance (multiple inheritance too)
Templates (classes and functions; template specialization)
Initialization Lists
Implicit constructors
Friend access
Namespaces
Anonymous unions
Better casts (type) type(var) static_cast<type> const_cast<type>
reinterpret_cast<type> dynamic_cast<type>
Inline functions
Enhanced static
Member function/data pointers
Virtual functions (pure)
Const pointers
mutable keyword
Anonymous namespaces
You don't need struct, union, enum tags
:: (scope resolution operator)
Function overloading
Operator overloading
Runtime type identification
C++ style includes
// Comments
Functions as an l-value (must return reference)
structs can include functions
this pointer
bool keyword (is it a C++ keyword?)

I/O mechanisms
STL

Thanks!

--
-Rob Hoelz
 
Reply With Quote
 
 
 
 
Micah Cowan
Guest
Posts: n/a
 
      12-20-2006
Rob Hoelz wrote:
> I've been compiling a list of the differences between C and C++, and
> I'd like to see how thorough I've been. Could any of you go over this
> list and see if I've missed anything?
>
> Here's the list:
>
> Mid-scope declarations
> Default function parameters
> new/delete operators
> Better implementation of const
> References
> Exception handling
> "Catch all" catch block


All catches are a difference from C... isn't the above line redundant
with the preceding line?

> Classes
> Constructors/Destructors
> Access modifiers
> Inheritance (multiple inheritance too)
> Templates (classes and functions; template specialization)
> Initialization Lists
> Implicit constructors
> Friend access
> Namespaces
> Anonymous unions
> Better casts (type) type(var) static_cast<type> const_cast<type>
> reinterpret_cast<type> dynamic_cast<type>
> Inline functions
> Enhanced static
> Member function/data pointers
> Virtual functions (pure)
> Const pointers
> mutable keyword
> Anonymous namespaces
> You don't need struct, union, enum tags
> :: (scope resolution operator)
> Function overloading
> Operator overloading
> Runtime type identification
> C++ style includes
> // Comments
> Functions as an l-value (must return reference)
> structs can include functions


As may unions.

> this pointer
> bool keyword (is it a C++ keyword?)


Yes, it's a keyword in C++.

> I/O mechanisms


That description's pretty vague... obviously C has I/O mechanisms...

> STL


This is more of a list of differences between the 1990 version of C and
C++, rather than differences between C (which is now defined by the
1999 standard) and C++. If it were the latter, differences such as //
comments, bool (though it's not a keyword in C), inline functions, and
"Mid-scope declarations" would go away (though there would still be
some related differences). New differences such as C's "restrict"
keyword, compound literals, C's complex number implementation, and
Variable Length Arrays would need to be listed.

Here are some further differences between C90 and C++ that spring to
mind:

Removal of non-prototype function declarations.
Removal of implicit int (also removed from C99)
The type of string literals (const char[] vs char*)
The type of character literals (char vs int)
Implicit conversion to/from void* has been removed.
main() cannot be called recursively in C++ (can in C)
Conversion between object pointers and (unsigned char *) is not
explicitly well-defined as it is in C

.... if you really want to be pedantic about such differences, you could
sit the C and C++ language specifications side-by-side, and compare
differences in related sections. That would take quite a while, but you
could end up with a pretty exhaustive list that way

-Micah

 
Reply With Quote
 
 
 
 
Clark S. Cox III
Guest
Posts: n/a
 
      12-20-2006
Rob Hoelz wrote:
> I've been compiling a list of the differences between C and C++, and
> I'd like to see how thorough I've been. Could any of you go over this
> list and see if I've missed anything?
>
> Here's the list:
>
> Mid-scope declarations


Min-scope declarations are in C99 as well

> Default function parameters
> new/delete operators
> Better implementation of const
> References
> Exception handling
> "Catch all" catch block


I'd say that "Catch all" catch blocks falls under "Exception handling"

> Classes
> Constructors/Destructors
> Access modifiers
> Inheritance (multiple inheritance too)
> Templates (classes and functions; template specialization)
> Initialization Lists
> Implicit constructors
> Friend access
> Namespaces
> Anonymous unions
> Better casts (type) type(var) static_cast<type> const_cast<type>
> reinterpret_cast<type> dynamic_cast<type>
> Inline functions


Inline functions are in C99

> Enhanced static


What do you mean by this?

> Member function/data pointers
> Virtual functions (pure)
> Const pointers


Const pointers are in C

> mutable keyword
> Anonymous namespaces
> You don't need struct, union, enum tags
> :: (scope resolution operator)
> Function overloading
> Operator overloading
> Runtime type identification
> C++ style includes


What do you mean by "C++ style includes"?

> // Comments


These are available in C99 also

> Functions as an l-value (must return reference)
> structs can include functions
> this pointer
> bool keyword (is it a C++ keyword?)


Yes, it is a keyword. (C99 has the _Bool keyword, BTW)

>
> I/O mechanisms
> STL
>
> Thanks!
>



--
Clark S. Cox III
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Rob Hoelz
Guest
Posts: n/a
 
      12-20-2006
"Clark S. Cox III" <(E-Mail Removed)> wrote:

> Rob Hoelz wrote:
> > I've been compiling a list of the differences between C and C++, and
> > I'd like to see how thorough I've been. Could any of you go over
> > this list and see if I've missed anything?
> >
> > Here's the list:
> >
> > Mid-scope declarations

>
> Min-scope declarations are in C99 as well


I've based this off of C89.

>
> > Default function parameters
> > new/delete operators
> > Better implementation of const
> > References
> > Exception handling
> > "Catch all" catch block

>
> All catches are a difference from C... isn't the above line redundant
> with the preceding line?
> I'd say that "Catch all" catch blocks falls under "Exception handling"


If I post this list elsewhere, I will remove this.

>
> > Classes
> > Constructors/Destructors
> > Access modifiers
> > Inheritance (multiple inheritance too)
> > Templates (classes and functions; template specialization)
> > Initialization Lists
> > Implicit constructors
> > Friend access
> > Namespaces
> > Anonymous unions
> > Better casts (type) type(var) static_cast<type> const_cast<type>
> > reinterpret_cast<type> dynamic_cast<type>
> > Inline functions

>
> Inline functions are in C99


Once again, C89.

>
> > Enhanced static

>
> What do you mean by this?


I mean that the meaning of static in C++ has been expanded from the
original meaning in C.

>
> > Member function/data pointers
> > Virtual functions (pure)
> > Const pointers

>
> Const pointers are in C
>
> > mutable keyword
> > Anonymous namespaces
> > You don't need struct, union, enum tags
> > :: (scope resolution operator)
> > Function overloading
> > Operator overloading
> > Runtime type identification
> > C++ style includes

>
> What do you mean by "C++ style includes"?


I mean include statements like this:
#include <cstring>
#include <iostream>

>
> > // Comments

>
> These are available in C99 also
>
> > Functions as an l-value (must return reference)
> > structs can include functions

> As may unions.


Thanks for this addition!

> > this pointer
> > bool keyword (is it a C++ keyword?)

>
> Yes, it is a keyword. (C99 has the _Bool keyword, BTW)
>
> >
> > I/O mechanisms

>
> That description's pretty vague... obviously C has I/O mechanisms...


By this I simply meant the difference between using stdio and iostream.

> > STL
> >
> > Thanks!
> >

>
>


Thanks for all of the corrections, feel free to keep them coming!

--
-Rob Hoelz
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      12-20-2006
Rob Hoelz wrote:

> structs can include functions


As they can in C.

--
Ian Collins.
 
Reply With Quote
 
Rob Hoelz
Guest
Posts: n/a
 
      12-20-2006
Ian Collins <(E-Mail Removed)> wrote:

> Rob Hoelz wrote:
>
> > structs can include functions

>
> As they can in C.
>


rob@TheRing ~ $ gcc -o test test.c
test.c:6: error: field 'foo' declared as a function

Doesn't seem like it.

-Rob Hoelz
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      12-20-2006
Rob Hoelz wrote:
> Ian Collins <(E-Mail Removed)> wrote:
>
>
>>Rob Hoelz wrote:
>>
>>
>>>structs can include functions

>>
>>As they can in C.
>>

> rob@TheRing ~ $ gcc -o test test.c
> test.c:6: error: field 'foo' declared as a function
>
> Doesn't seem like it.


struct X
{
void (*fn)( struct X* );
};

void xFn( struct X* this ) {}

int main()
{
struct X x;
x.fn = xFn;
}

--
Ian Collins.
 
Reply With Quote
 
Rob Hoelz
Guest
Posts: n/a
 
      12-20-2006
Ian Collins <(E-Mail Removed)> wrote:

> Rob Hoelz wrote:
> > Ian Collins <(E-Mail Removed)> wrote:
> >
> >
> >>Rob Hoelz wrote:
> >>
> >>
> >>>structs can include functions
> >>
> >>As they can in C.
> >>

> > rob@TheRing ~ $ gcc -o test test.c
> > test.c:6: error: field 'foo' declared as a function
> >
> > Doesn't seem like it.

>
> struct X
> {
> void (*fn)( struct X* );
> };
>
> void xFn( struct X* this ) {}
>
> int main()
> {
> struct X x;
> x.fn = xFn;
> }
>


But that's a function pointer, not a function...

--
-Rob Hoelz
 
Reply With Quote
 
Stuart Redmann
Guest
Posts: n/a
 
      12-20-2006
Rob Hoelz wrote:
> "Clark S. Cox III" <(E-Mail Removed)> wrote:
>>Rob Hoelz wrote:
>>
>>>I've been compiling a list of the differences between C and C++, and
>>>I'd like to see how thorough I've been. Could any of you go over
>>>this list and see if I've missed anything?
>>>


[snipped items from his list]

>>>C++ style includes

>>
>>What do you mean by "C++ style includes"?

>
>
> I mean include statements like this:
> #include <cstring>
> #include <iostream>


In which regards does this #include statement differ from the C #include
statement? AFAIK, the pre-compiler from C89 only differs from C++
pre-compiler with regard to the handling of one-line-comments.

Regards,
Stuart
 
Reply With Quote
 
Rob Hoelz
Guest
Posts: n/a
 
      12-20-2006
Stuart Redmann <(E-Mail Removed)> wrote:

> Rob Hoelz wrote:
> > "Clark S. Cox III" <(E-Mail Removed)> wrote:
> >>Rob Hoelz wrote:
> >>
> >>>I've been compiling a list of the differences between C and C++,
> >>>and I'd like to see how thorough I've been. Could any of you go
> >>>over this list and see if I've missed anything?
> >>>

>
> [snipped items from his list]
>
> >>>C++ style includes
> >>
> >>What do you mean by "C++ style includes"?

> >
> >
> > I mean include statements like this:
> > #include <cstring>
> > #include <iostream>

>
> In which regards does this #include statement differ from the C
> #include statement? AFAIK, the pre-compiler from C89 only differs
> from C++ pre-compiler with regard to the handling of
> one-line-comments.
>
> Regards,
> Stuart


Here's the difference:
#include <string.h> is a C-style include. It includes the file
extension.

#include <iostream> is a C++-style include; it doesn't include the
extension.

#include <cstring>

This is another C++-style include; including the standard C string
library. This has the same effect as the C-style include I demonstrated
before; but this one will only work in C++.

I realize the difference is rather superficial, but like I said, I just
wanted to be thorough.
--
-Rob Hoelz
 
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
Can External+Internal Lan Card be on 1 w/l on diff. network segmen =?Utf-8?B?U0E0MDU=?= Wireless Networking 0 10-07-2005 06:06 PM
Diff CSS styles for diff INPUT TYPE='s? A Traveler ASP .Net 6 08-31-2004 09:17 PM
[ANN] Diff::LCS 1.1.0, Diff::LCS 1.0.4 Austin Ziegler Ruby 3 08-09-2004 06:34 AM
diff Process under diff users Cyril Vi?ville Perl 1 06-29-2004 06:22 PM
Same sessionID retuned to diff browsers in diff machines Berrucho ASP .Net 2 12-05-2003 02:23 PM



Advertisments