Followings are from Internet source (openasthra.com). Some are interesting and I didn't notice before:
- sizeof (’1′) == sizeof (int) in C; but it is sizeof (char) in C++. So we get the result 4 and 1 with compiler gcc and g++, respectively.
- Usually you should not use *alloc()/free() in C++, but they are the only such functions in C.
- Functions need not be prototyped in C, but it is a must in C++.
- struct a {
struct b {
int a;
};
};
struct b b; /*allowed in C, but not in C++ */
not quite sure this one, but it has error in g++ compiler(error: aggregate 'b b' has incomplete type and cannot be defined. With following codes:
sturct a {
int a;
}
struct a a;
some compilers are OK, some will report error. - const int b = 1; /* allowed in C and C++ */
const int a ; /* allowed in C, not in C++ */ - global variables can be defined more than once in C, not in C++
int a; /* works in C, C++ */
int a = 10 ; /* works in C, not in C++ */
int main()
{...} - const a; /* equivalent to const in a; in C, illegal in C++ */
- char s[7] = "1234567"; /* allowed in C, error in C++ */
- K&R style function definitions are not allowed in C++, such as:
void foo(a)
int a;
{...}
No comments:
Post a Comment