本文介紹了C 在哪里不是 C++ 的子集?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我在很多書中都讀到 C 是 C++ 的一個(gè)子集.
I read in a lot of books that C is a subset of C++.
有些書說 C 是 C++ 的子集,除了小細(xì)節(jié).
Some books say that C is a subset of C++, except for the little details.
在哪些情況下代碼可以用 C 編譯,但不能用 C++ 編譯?
What are some cases when code will compile in C, but not C++?
推薦答案
如果將 C89
與 C++
進(jìn)行比較,那么這里有一些事情
If you compare C89
with C++
then here are a couple of things
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函數(shù)定義樣式
int b(a) int a; { } // ill-formed: grammar error
嵌套結(jié)構(gòu)在 C++ 中具有類作用域
struct A { struct B { int a; } b; int c; };
struct B b; // ill-formed: b has incomplete type (*not* A::B)
無默認(rèn)整數(shù)
auto a; // ill-formed: type-specifier missing
<小時(shí)>
C99 增加了很多其他情況
C99 adds a whole lot of other cases
// ill-formed: invalid syntax
void f(int p[static 100]) { }
沒有變長(zhǎng)數(shù)組
// ill-formed: n is not a constant expression
int n = 1;
int an[n];
沒有靈活的數(shù)組成員
// 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);
這篇關(guān)于C 在哪里不是 C++ 的子集?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!