嵌套函数的C标准的一部分? [英] Are nested functions part of C standard?

查看:74
本文介绍了嵌套函数的C标准的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我遇到了,我从来没有听说过的嵌套函数。难道只有GNU C的一部分?

Today i came across nested functions which i had never heard of. Is it only part of GNU C?

下面是嵌套函数的维基百科的例子。

Here is a wikipedia example of nested function.

float E(float x)
{
    float F(float y)
    {
        return x + y;
    }
    return F(3);
}

从code,它看起来像嵌套函数类型的C ++内联函数。那么,是不是可以取出嵌套函数的地址?

From the code, it looks like nested functions are sort of C++ inline functions. So, is it possible to take out the address of nested function?

编辑:

由亚当给出的海湾合作​​委员会链接说,嵌套函数的code动态创建堆栈。但你如何运行堆栈code?难道不应该在那里的code段。

The gcc link given by Adam says that nested function's code is created dynamically on stack. But how do you run code from stack? Shouldn't it be there in code segment.

推荐答案

没有,他们不是C或C ++标准的一部分。他们是一个GNU扩展的GCC编译器。请参阅 GCC手册了解详情。它实际上是可能采取的嵌套函数,它使用一种称为技术完成的地址的蹦床,但要注意手册中列出的注意事项的。

No, they are not part of the C or C++ standard. They are a GNU extension in the GCC compiler. See the GCC manual for more information. It is actually possible to take the address of a nested function, which is done using a technique called trampolines, but beware of the caveats listed in the manual.

这篇关于嵌套函数的C标准的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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