我在很多书中读到C是C++的子集.
有些书说C是C++的子集,except for the little details.
在哪些情况下,代码可以用C编译,但不能用C++编译?
我在很多书中读到C是C++的子集.
有些书说C是C++的子集,except for the little details.
在哪些情况下,代码可以用C编译,但不能用C++编译?
如果你比较C89
和C++
,那么这里有几件事
int n;
int n; // ill-formed: n already defined
int a[1];
int (*ap)[] = &a; // ill-formed: a does not have type int[]
int b(a) int a; { } // ill-formed: grammar error
struct A { struct B { int a; } b; int c; };
struct B b; // ill-formed: b has incomplete type (*not* A::B)
auto a; // ill-formed: type-specifier missing
C99增加了很多其他情况
// ill-formed: invalid syntax
void f(int p[static 100]) { }
// ill-formed: n is not a constant expression
int n = 1;
int an[n];
// ill-formed: fam has incomplete type
struct A { int a; int fam[]; };
// ill-formed: two names for one parameter?
void copy(int *restrict src, int *restrict dst);