C在哪里不是C ++的子集? [英] Where is C not a subset of C++?

查看:55
本文介绍了C在哪里不是C ++的子集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过很多书,其中C是C ++的子集。

I read in a lot of books that C is a subset of C++.

有些书说C是C ++的子集,除了一些小细节。

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 ++ ,这是几件事

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[] and int[N] not compatible (no compatible types in C++)

int a[1];
int (*ap)[] = &a; // ill-formed: a does not have type int[]



没有K&R函数定义样式



No K&R function definition style

int b(a) int a; { } // ill-formed: grammar error



嵌套结构在C ++中具有类作用域



Nested struct has class-scope in C++

struct A { struct B { int a; } b; int c; };
struct B b; // ill-formed: b has incomplete type (*not* A::B)



无默认值int



No default int

auto a; // ill-formed: type-specifier missing






C99添加了很多其他情况


C99 adds a whole lot of other cases

// ill-formed: invalid syntax
void f(int p[static 100]) { }



没有可变长度的数组



No variable length arrays

// ill-formed: n is not a constant expression
int n = 1;
int an[n];



没有灵活的数组成员



No flexible array member

// ill-formed: fam has incomplete type
struct A { int a; int fam[]; }; 



没有限制限定符来帮助别名分析



No restrict qualifier for helping aliasing analysis

// ill-formed: two names for one parameter?
void copy(int *restrict src, int *restrict dst);

这篇关于C在哪里不是C ++的子集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆