3 回答

TA貢獻1789條經驗 獲得超8個贊
如果你比較C89帶著C++下面是幾件事
C+中沒有暫定定義
int n;
int n; // ill-formed: n already defined
int[]和int[N]不兼容(C+中沒有兼容類型)
int a[1];
int (*ap)[] = &a; // ill-formed: a does not have type int[]
無K&R函數定義樣式
int b(a) int a; { } // ill-formed: grammar error
嵌套結構在C+中具有類范圍。
struct A { struct B { int a; } b; int c; };
struct B b; // ill-formed: b has incomplete type (*not* A::B)
沒有默認的int
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);

TA貢獻1828條經驗 獲得超4個贊
C+也有新的關鍵字。以下是有效的C代碼,但不能在C+下編譯:
int class = 1;
int private = 2;
int public = 3;
int virtual = 4;
- 3 回答
- 0 關注
- 607 瀏覽
添加回答
舉報