gcc中嵌套函数是一件坏事吗? [英] Are nested functions a bad thing in gcc ?

查看:150
本文介绍了gcc中嵌套函数是一件坏事吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道嵌套函数不是标准C的一部分,但是因为它们存在于gcc中(并且gcc是我唯一关心的唯一编译器),所以我倾向于经常使用它们。



这是一件坏事吗?如果是这样,你能告诉我一些令人讨厌的例子吗?
gcc中嵌套函数的状态是什么?它们是否会被移除?

解决方案

嵌套函数实际上不会做任何你无法做的非嵌套(这就是为什么C和C ++都不提供它们)。你说你对其他编译器不感兴趣 - 这可能是假的,但谁知道未来会带来什么?我会避免他们,以及所有其他海湾合作委员会的增强。

一个小故事来说明这一点 - 我曾经为英国Polytechinc工作,主要使用DEC箱 - 特别是DEC-10和一些VAXen。所有的工程学院都在他们的代码中使用了FORTRAN的许多DEC扩展 - 他们确信我们将永远是DEC商店。然后,我们用IBM大型机取代了DEC-10,而大型机FORTRAN编译器不支持任何扩展。那天我有很多哭泣和咬牙切齿,我可以告诉你。我自己的FORTRAN代码(一个8080模拟器)在几个小时内移植到了IBM(几乎所有的代码都是学习如何驱动IBM编译器),因为我已经将它编写在了bog标准的FORTRAN-77中。


I know that nested functions are not part of the standard C, but since they're present in gcc (and the fact that gcc is the only compiler i care about), i tend to use them quite often.

Is this a bad thing ? If so, could you show me some nasty examples ? What's the status of nested functions in gcc ? Are they going to be removed ?

解决方案

Nested functions really don't do anything that you can't do with non-nested ones (which is why neither C nor C++ provide them). You say you are not interested in other compilers - well this may be atrue at this moment, but who knows what the future will bring? I would avoid them, along with all other GCC "enhancements".

A small story to illustrate this - I used to work for a UK Polytechinc which mostly used DEC boxes - specifically a DEC-10 and some VAXen. All the engineering faculty used the many DEC extensions to FORTRAN in their code - they were certain that we would remain a DEC shop forever. And then we replaced the DEC-10 with an IBM mainframe, who's FORTRAN compiler didn't support any of the extensions. There was much wailing and gnashing of teeth on that day, I can tell you. My own FORTRAN code (an 8080 simulator) ported over to the IBM in a couple of hours (almost all taken up with learning how to drive the IBM compiler), because I had written it in bog-standard FORTRAN-77.

这篇关于gcc中嵌套函数是一件坏事吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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