使用gcc而不是g ++编译的代码段 [英] Piece of code that compiles with gcc but not g++
问题描述
可能的重复项:
这是合法的C ++代码吗?
C ++的C ++子集 - >在哪里不?示例?
任何人都可以想出一段用gcc编译的代码或任何其他C编译器,并且不编译g ++或任何其他C ++编译器?
Could anybody come up with a piece of code that compiles with gcc or any other C compiler, and doesn't compile g++ or any other C++ compiler?
更新:
我不是只是关键字
UPDATE: I don't mean just keywords
UPDATE2:
谢谢大家的答案。显然,版主对C和C ++之间的细微差异不太热心。
UPDATE2: Thank you All for answers. Apparently moderators were less enthusiastic than I was about subtle differences between C and C++.
UPDATE3:
给主持人:您可以将它与我上一个问题合并主题,你建议吗?将这两个问题集中在一起是非常有意义的。
UPDATE3: to moderators: could you merge it with my previous question on the topic, as you suggested? It makes perfect sense to keep these two question together.
推荐答案
#include <stdlib.h>
int main()
{
char* s = malloc(128);
return 0;
}
这将使用gcc进行编译,但不能使用g ++。 C ++需要从 void *
显式转换,而C不需要。
This will compile with gcc, but not with g++. C++ requires an explicit cast from void*
here, whereas C does not.
这篇关于使用gcc而不是g ++编译的代码段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!