为什么没有本地功能? [英] Why no local functions ?

查看:97
本文介绍了为什么没有本地功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。


我现在很多时间编程C ++并且我还不知道这个简单的事情:什么'''这是本地功能的问题,所以他们不属于这个问题。

C ++?


肯定会有很多人会发现它们非常有用。 gcc有

它们作为非标准选项,但只有在编译C语言代码时,

所以我担心可能有一些不明确的原因,为什么本地函数是

不容易用C ++处理,我还不知道。


任何人都知道在C ++中支持本地函数有什么问题?


谢谢

Timothy Madden

罗马尼亚

Hello all.

I program C++ since a lot of time now and I still don''t know this simple
thing: what''s the problem with local functions so they are not part of
C++ ?

There surely are many people who will find them very helpfull. gcc has
them as a non-standard option, but only when compiling C language code,
so I''m afraid there might be some obscure reason why local functions are
not so easy to be dealt with in C++, which I do not yet know.

Anyone knows what is the problem with supporting local functions in C++ ?

Thank you
Timothy Madden
Romania

推荐答案

本地功能是什么意思?文件范围内的函数?

What do you mean by ''local'' functions? Functions at file scope?


* Timothy Madden:
* Timothy Madden:

我从很多时候开始编程C ++我还是不知道这个简单的事情:本地函数的问题是什么,所以它们不是C ++的一部分?

I program C++ since a lot of time now and I still don''t know this simple
thing: what''s the problem with local functions so they are not part of
C++ ?




C ++以本地

类的成员函数的形式支持本地函数。


这些函数无法访问封闭范围的变量,

,特别是他们无法访问封闭函数的

参数。


主要原因是这种限制可能是局部函数à

la Pascal效率低下(它们需要一个链接的堆栈结构,看起来好像是'b $ b up'Dijkstra显示),并没有任何帮助解决问题,并且如果你真的需要它们,可以很容易地模仿



另一个限制是,就像我ecall,他们没有链接,例如

你不能使用本地定义的函数作为模板参数。


我不确定原因对于后一个限制。


-

答:因为它弄乱了人们通常阅读文本的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的是什么?



C++ supports local functions in the form of member functions of local
classes.

Such functions do not have access to the enclosing scope''s variables,
and in particular they do not have access to the enclosing function''s
arguments.

The main reason for that restriction is probably that local functions à
la Pascal are inefficient (they require a linked stack structure, look
up "Dijkstra displays"), not really of any help in solving problems, and
can be easily emulated if you _really_ need them.

Another restriction is that, as I recall, they do not have linkage, e.g.
you cannot use a locally defined function as a template parameter.

I''m not sure of the reason for that latter restriction.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


da ******** @ warpmail.net 写道:
本地功能是什么意思?文件范围内的函数?
What do you mean by ''local'' functions? Functions at file scope?




不,我认为他的意思是Pascal就像本地函数一样。


例如


int f()

{

int i;


void f()// A

{

i = 2; //链接到int f():: i

}


f(); //链接到int f():: void f()


返回i; //返回2

}



No, I think he means Pascal like local functions.

e.g.

int f()
{
int i;

void f() // A
{
i = 2; // links to int f()::i
}

f(); // links to int f()::void f()

return i; // returns 2
}


这篇关于为什么没有本地功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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