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

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

问题描述

我知道嵌套函数不是标准 C 的一部分,但由于它们存在于 gcc 中(事实上 gcc 是我关心的唯一编译器),我倾向于经常使用它们.

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.

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

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 ?

推荐答案

嵌套函数确实不会执行非嵌套函数无法执行的任何操作(这就是 C 和 C++ 都不提供它们的原因).你说你对其他编译器不感兴趣——现在这可能是真的,但谁知道未来会带来什么?我会避免使用它们,以及所有其他 GCC增强功能".

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".

一个小故事来说明这一点 - 我曾经在一家主要使用 DEC 盒的英国理工学院工作 - 特别是 DEC-10 和一些 VAXen.所有的工程学院都在他们的代码中使用了许多 DEC 对 FORTRAN 的扩展——他们确信我们将永远保持 DEC 的地位.然后我们用 IBM 大型机替换了 DEC-10,它的 FORTRAN 编译器不支持任何扩展.我可以告诉你,那天有很多哀号和咬牙切齿的声音.我自己的 FORTRAN 代码(一个 8080 模拟器)在几个小时内移植到了 IBM(几乎全部都在学习如何驱动 IBM 编译器),因为我是用 bog 标准的 FORTRAN-77 编写的.

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, the FORTRAN compiler of which 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天全站免登陆