473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

diff C C++

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<typeconst_cast<type>
reinterpret_cast<typedynamic_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
Dec 20 '06 #1
17 1914
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<typeconst_cast<type>
reinterpret_cast<typedynamic_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

Dec 20 '06 #2
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<typeconst_cast<type>
reinterpret_cast<typedynamic_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
cl*******@gmail.com
Dec 20 '06 #3
"Clark S. Cox III" <cl*******@gmail.comwrote:
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<typeconst_cast<type>
reinterpret_cast<typedynamic_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
Dec 20 '06 #4
Rob Hoelz wrote:
structs can include functions
As they can in C.

--
Ian Collins.
Dec 20 '06 #5
Ian Collins <ia******@hotmail.comwrote:
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
Dec 20 '06 #6
Rob Hoelz wrote:
Ian Collins <ia******@hotmail.comwrote:

>>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.
Dec 20 '06 #7
Ian Collins <ia******@hotmail.comwrote:
Rob Hoelz wrote:
Ian Collins <ia******@hotmail.comwrote:

>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
Dec 20 '06 #8
Rob Hoelz wrote:
"Clark S. Cox III" <cl*******@gmail.comwrote:
>>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
Dec 20 '06 #9
Stuart Redmann <De*******@web.dewrote:
Rob Hoelz wrote:
"Clark S. Cox III" <cl*******@gmail.comwrote:
>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.his a C-style include. It includes the file
extension.

#include <iostreamis 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
Dec 20 '06 #10
On Dec 20, 11:30 am, Rob Hoelz <h...@wisc.eduwrote:
Stuart Redmann <DerTop...@web.dewrote:
Rob Hoelz wrote:
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,
StuartHere's the difference:
#include <string.his a C-style include. It includes the file
extension.

#include <iostreamis 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++.
Not exactly the same effect AFAIK, <cstringplaces the functions and
whatnot in <string.hin the std-namespace.

--
Erik Wikström

Dec 20 '06 #11
Rob Hoelz <ho***@wisc.eduwrote:
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:
[list redacted]

A fairly comprehensive document detailing the incompatibilities between
C++ and various versions of C can be found here:

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

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Dec 20 '06 #12

Rob Hoelz wrote:
Ian Collins <ia******@hotmail.comwrote:
Rob Hoelz wrote:
Ian Collins <ia******@hotmail.comwrote:
>
>
>>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
I think Rob is right. If C can have a function definition inside a
struct, would the struct become a "class" ?

Anyway, a struct having a function pointer should be in C from day one.

Dec 21 '06 #13
Ian Collins wrote:
Rob Hoelz wrote:
>Ian Collins <ia******@hotmail.comwrote:

>>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;
}
That is a struct that contains a pointer (nothing special there), *not*
a struct that contains a function. A struct that contains a function
looks like this (valid C++, invalid C):

struct X
{
void fn() {}
};
--
Clark S. Cox III
cl*******@gmail.com
Dec 22 '06 #14

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
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<typeconst_cast<type>
reinterpret_cast<typedynamic_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)
I suspect that the above statement is _NOT_ corrrect. Here is an
example that compiles on Comeau that shows a function being used as an
l-value returning a pointer, _NOT_ a reference. I suspect this code
would compile on C compiler as well (substituting printf() etc. for
cout etc of course).

#include <iostream>
int * func();
int main()
{
*func() = 20; // will print 10 the first time
func(); // should print 20 the second time.
return 0;
}

int * func()
{
static int i = 10;
std::cout << i << std::endl;
return &i;
}

structs can include functions
this pointer
bool keyword (is it a C++ keyword?)

I/O mechanisms
STL

Thanks!

--
-Rob Hoelz
Dec 22 '06 #15
blangela wrote:
Rob Hoelz wrote:
>Functions as an l-value (must return reference)

I suspect that the above statement is _NOT_ corrrect. Here is an
example that compiles on Comeau that shows a function being used as an
l-value returning a pointer, _NOT_ a reference.
The function is not returning an lvalue, it is returning a pointer.
Dereferencing that pointer (which is an rvalue) yields an lvalue.
I suspect this code
would compile on C compiler as well (substituting printf() etc. for
cout etc of course).

#include <iostream>
int * func();
int main()
{
*func() = 20; // will print 10 the first time
func(); // should print 20 the second time.
return 0;
}

int * func()
{
static int i = 10;
std::cout << i << std::endl;
return &i;
}
--
Clark S. Cox III
cl*******@gmail.com
Dec 22 '06 #16

Clark S. Cox III wrote:
blangela wrote:
Rob Hoelz wrote:
Functions as an l-value (must return reference)
I suspect that the above statement is _NOT_ corrrect. Here is an
example that compiles on Comeau that shows a function being used as an
l-value returning a pointer, _NOT_ a reference.

The function is not returning an lvalue, it is returning a pointer.
Dereferencing that pointer (which is an rvalue) yields an lvalue.
I suspect this code
would compile on C compiler as well (substituting printf() etc. for
cout etc of course).

#include <iostream>
int * func();
int main()
{
*func() = 20; // will print 10 the first time
func(); // should print 20 the second time.
return 0;
}

int * func()
{
static int i = 10;
std::cout << i << std::endl;
return &i;
}

--
Clark S. Cox III
cl*******@gmail.com
The end result is the same - that a function can be invoked on the
left hand side of an assignment operator. So even why bother mentioning
the fact that a C++ function can return an L-value?

Dec 23 '06 #17
blangela wrote:
Clark S. Cox III wrote:
>blangela wrote:
>>Rob Hoelz wrote:
Functions as an l-value (must return reference)
I suspect that the above statement is _NOT_ corrrect. Here is an
example that compiles on Comeau that shows a function being used as an
l-value returning a pointer, _NOT_ a reference.
The function is not returning an lvalue, it is returning a pointer.
Dereferencing that pointer (which is an rvalue) yields an lvalue.
>>I suspect this code
would compile on C compiler as well (substituting printf() etc. for
cout etc of course).

#include <iostream>
int * func();
int main()
{
*func() = 20; // will print 10 the first time
func(); // should print 20 the second time.
return 0;
}

int * func()
{
static int i = 10;
std::cout << i << std::endl;
return &i;
}

The end result is the same - that a function can be invoked on the
left hand side of an assignment operator. So even why bother mentioning
the fact that a C++ function can return an L-value?
Because it is a difference between the two languages; and that is what
the OP was looking for.
--
Clark S. Cox III
cl*******@gmail.com
Dec 23 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Charley | last post by:
I've got a diff file that I think is a patch for a bunch of file in a directory. How do I apply this file? I thought it was #patch myfile.diff But that does nothing. I must be missing...
0
by: python | last post by:
Hi- I have a lot of monthly time series data. I need to be able to compare two dates and get the number of months that they are apart. The datetime module is a daily-frequency data type. ...
3
by: Nick Allen | last post by:
After using ndiff from difflib, the function restore would return the sequence that generated the delta. Unfortunately, restore does not do the same for unified_diff. I do not see any similar...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
6
by: Igor Shevchenko | last post by:
Hi! Suppose I have "pg_dump -s" of two pg installs, one is "dev", another is "production". Their schemas don't differ too much, and I want to get a "diff -u"-like schema diff so I can quickly...
4
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on...
3
by: AirYT | last post by:
Hello, I'm looking for an implementation for diffing 2 (text) files and spitting out the output using php only. i would like to extend this to use ftp to diff two files on two ftp servers, or...
4
by: Shug | last post by:
Hi, We're reformatting a lot of our project code using the excellent uncrustify beautifier. However, to gain confidence that it really is only changing whitespace (forget { } issues for just...
6
by: Aaron Gray | last post by:
Hi, I am working on an HTML WYSISYG Wiki and need to display a diff page like WikiPedia does if two people edit a file at the same time to give the second user the diff. Basically with additions...
2
by: akshaycjoshi | last post by:
I have got one tree tree view control.I have three levels in it. Example- Root1 ------->child1 ------->child2 ---------------->child1 ---------------->child2 ------->child3 Root2
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.