一段使用 gcc 编译但不使用 g++ 的代码
有人能想出一段用 gcc 或任何其他 C 编译器编译的代码,而不编译 g++ 或任何其他 C++ 编译器吗?
更新: 我的意思不仅仅是关键字
UPDATE2: 谢谢大家的解答。显然,版主对 C 和 C++ 之间的细微差别没有我那么热情。
更新3: 主持人:您能否按照您的建议将其与我之前关于该主题的问题合并?将这两个问题放在一起是非常有意义的。
Possible Duplicates:
Is this a legitimate C++ code?
“C subset of C++” -> Where not ? examples ?
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:
Thank you All for answers. Apparently moderators were less enthusiastic than I was about subtle differences between C and C++.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这将使用 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.编辑:另一个例子
Edit: another example
尝试
记住使用严格标志进行编译。
Try
Remember to compile with the strict flags.
怎么样
这似乎是 C++ 设计中一个相当大的突破性变化,但事实就是如此。
How about
That seems a pretty big breaking change in the design of C++, but it is what it is.
字符大小如何:
更糟糕的是它编译但在运行时产生不同的输出。
这实际上让我们想知道为什么会这样?
即使对象的大小不同,它也适用于两个编译器。
What about character size:
Even worse is that it compiles but produces different output at runtime.
This actually makes we wonder why this works?
It works on both compilers even though the size of the objects are different.
void*
上的指针算术:pointer arithmetics on
void*
: