是否仍将C代码视为C ++? [英] Is C code still considered C++?

查看:30
本文介绍了是否仍将C代码视为C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此答案的评论让我想知道.我一直认为C是C ++的适当子集,也就是说,任何有效的C代码都是有效的C ++代码扩展.我说错了吗?是否可以编写无效的C ++代码的有效C程序?

The comment to this answer got me wondering. I've always thought that C was a proper subset of C++, that is, any valid C code is valid C++ code by extension. Am I wrong about that? Is it possible to write a valid C program that is not valid C++ code?

这确实类似于这个问题.

推荐答案

通常,是的,C代码被视为C ++代码.

In general, yes C code is considered C++ code.

但是从严格意义上讲,C不是合适的子集.有几个例外.

But C is not a proper subset in a strict sense. There are a couple of exceptions.

以下是C中一些有效的内容,而这些在C ++中是无效的:

Here are some valid things in C that are not valid in C++:

int *new;//<-- new is not a keyword in C
char *p = malloc(1024); //void * to char* without cast 

也有更多示例,但是您明白了.

There are more examples too, but you get the idea.

我以前在类似的问题此处.

这篇关于是否仍将C代码视为C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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